我正在做一项作业,将一个新标签添加到我们将要进行标注的 JSON 请求中。请求如下。
{
"Version": "1.0",
"RequestingSystemName": "SFORCECS",
"InsuredInformation": {
"Zipcode": "12335",
"StateProvinceCode": "CA",
"PhoneNumber": "(111) 111-2222",
"MiddleName": null,
"LastName": "ABC",
"FirstName": "DEF",
"City": "PLACEWI",
"BirthDate": "1950-01-01",
"AddressLine3": null,
"AddressLine2": null,
"AddressLine1": "111 123 Drive"
},
"BeneficiaryList": [
{
"RelationShipEnum": "Nephew",
"Relationship": 18,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "XYZ DEQ"
},
{
"RelationShipEnum": "Niece",
"Relationship": 20,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "DEQ XYZ"
}
],
"ApplicationInformation": {
"SignedDateTime": "2010-01-01T01:01:01.000Z",
"ProductIdentifier": "1",
"MarketingSequenceNumber": "11111111111",
"EmailAddress": null,
"ContractNumber": "1111111",
"BasicAmount": "1000",
"AgentID": "12345"
}
}
现在,我的任务是更改受益人信息请求。它应该如下所示。
"BeneficiaryList": {"Beneficiary":[
{
"RelationShipEnum": "Nephew",
"Relationship": 18,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "XYZ DEQ"
},
{
"RelationShipEnum": "Niece",
"Relationship": 20,
"PrimaryIndicator": 0,
"Percentage": null,
"FullName": "DEQ XYZ"
}
]},
有人可以帮忙吗?生成受益人信息请求的顶点类如下。
public class ReqBasic{
public class Beneficiary{
public Beneficiary(){}
public Beneficiary(String FullName, Integer PrimaryIndicator, Integer Percentage, Integer Relationship){
this.FullName = FullName;
this.PrimaryIndicator = PrimaryIndicator;
this.Percentage = Percentage;
this.Relationship = Relationship;
}
public Beneficiary(String FullName, String PrimaryIndicator, Integer Percentage, String Relationship){
this.FullName = FullName;
this.setPrimaryIndicatorStr(PrimaryIndicator);
this.Percentage = Percentage;
this.setRelationshipStr(Relationship);
}
}
}
我不确定我需要进行哪些更改才能在受益人列表下添加受益人:标签。有人可以帮忙吗?
您共享的代码没有您需要的内容,但是在请求类中的某个地方,您应该有一个名为BeneficiaryList的变量,如下所示
List< Beneficiary> BeneficiaryList; //or = new List<Beneficiary>(); or Beneficiary[] depending on the coding style
您需要创建一个名为受益人(或任何您想要的(的新类,其中包含受益人列表
public class Beneficiaries{
List< Beneficiary> Beneficiary = new List<Beneficiary>();
public Beneficiaries(List<Beneficiary> beneficiaries){
Beneficiary.addAll(beneficiaries);
}
}
然后在您的类中,请求集 受益人列表 从受益人列表到新的受益人类
Beneficiaries BeneficiaryList = new Beneficiaries(beneficiaries);
显然,您的实施将取决于您的请求类的设置方式以及如何添加受益人,但您至少应该创建一个 add(...( 方法,这样您就不必更改太多代码