{
"requestBody": {
"newApplyNo": "E3100C02109000100000388",
"policy": {
"appliClient": [
{
"birthday": 983894400000,
"contactPhone": "",
"email": "fgf@qq.com",
"faxNumber": "XXXXXXXXXFW",
"identifyNumber": "110101200103078833",
"identifyType": "01",
"insuredAddress": "",
"insuredEName": "",
"insuredName": "周军",
"insuredType": "1",
"mobile": "13800138000",
"serialNo": 1,
"sex": "1"
}
],
"coverage": {
"itemList": [
{
"goodsCode": "LXSBCYLBX",
"goodsName": "留学生补充医疗保险(美国版)",
"insuredCount": 1,
"insuredIdvList": [
{
"age": 20,
"amount": 100000,
"applyDate": 1623945600000,
"basicsPolicy": {
"basicsPolicyCompany": "基础保单承保公司",
"basicsPolicyEndDate": 1658505599000,
"basicsPolicyNo": "基础保单保单号码",
"basicsPolicyStartDate": 1626969600000,
"graduateYear": "2023",
"insuredIdvChatNo": "WWWWWWWW",
"insuredSchool": "就读学校",
"linkerChatNo": "",
"linkerRelation": "",
"linkeridentifyNumber": ""
},
"beneficiary": [],
"benefitOrder": "",
"birthday": 983894400000,
"contactPhone": "",
"country": "",
"email": "15000000034@163.com",
"endDate": 1658419200000,
"identifyNumber": "110101200103072258",
"identifyType": "51",
"insuredAddress": "",
"insuredEName": "",
"insuredFlag": "1",
"insuredName": "周小军",
"insuredType": "1",
"itemNo": 1,
"linkerName": "",
"linkerPhone": "",
"mainInsuredFlag": "1",
"mobile": "15000000034",
"occupationCode": "A01001",
"occupationGrade": "A",
"occupationLevel": "1",
"occupationType": "A01",
"planCode": "LXSBCYLBX",
"planName": "留学生补充医疗保险(美国版)",
"relationToAppnt": "03",
"secondIdNum": "",
"secondIdType": "",
"serialNo": 1,
"sex": "",
"socialSecurityFlag": "",
"startDate": 1626969600000
}
],
"itemKind": [
{
"calculateInd": "1",
"clauseCode": "C01177",
"clauseName": "京东安联财产保险有限公司留学医疗补充保险条款",
"currency": "RMB",
"grossPremium": 1680,
"itemNo": 1,
"kindCode": "0422",
"kindInd": "1",
"kindName": "医疗保险金(含门急诊及住院医疗)",
"remark": "",
"sumInsured": 100000
}
],
"itemNo": 1,
"rationCount": 1
}
]
},
"main": {
"endDateStr": "2022-07-22 23:59:59",
"endorseNo": "P3100C02109000100001675-001",
"endorseText": "",
"endorseType": "06",
"giftType": "0",
"groupNo": "",
"inputDate": 1623945600000,
"isSupportFamily": "N",
"jFeeFlag": "0",
"policyNo": "P3100C02109000100001675",
"policyStatus": "1",
"proposalNo": "T3100C02109000100001675",
"renewalFlag": "0",
"signDate": 1623945600000,
"startDateStr": "2021-07-23 00:00:00",
"sumAmount": 100000,
"sumPremium": 1680,
"sumQuantity": 1,
"underWriteEndDate": 1626019200000,
"validDateStr": "2021-07-23 00:00:00"
},
"renewal": {},
"riskInfo": {
"DestAirport": "",
"FlightDate": "",
"FlightNumber": "",
"FlightTime": "",
"OriginAirport": "",
"arriveDate": "",
"arriveTime": ""
},
"sales": {
"agentCode": "AC600002",
"agentName": "非见费出单测试渠道"
}
}
},
"requestHead": {
"consumerID": "Apis",
"consumerSeqNo": "a5a3214bab664b979f66d63e89227d4b",
"transactionDate": 1626072102396
}
}
public static void main(String[] args) {
String line = "{\"requestBody\":{\"newApplyNo\":\"E3100C02109000100000388\",\"policy\":{\"appliClient\":[{\"birthday\":983894400000,\"contactPhone\":\"\",\"email\":\"fgf@qq.com\",\"faxNumber\":\"XXXXXXXXXFW\",\"identifyNumber\":\"110101200103078833\",\"identifyType\":\"01\",\"insuredAddress\":\"\",\"insuredEName\":\"\",\"insuredName\":\"周军\",\"insuredType\":\"1\",\"mobile\":\"13800138000\",\"serialNo\":1,\"sex\":\"1\"}],\"coverage\":{\"itemList\":[{\"goodsCode\":\"LXSBCYLBX\",\"goodsName\":\"留学生补充医疗保险(美国版)\",\"insuredCount\":1,\"insuredIdvList\":[{\"age\":20,\"amount\":100000,\"applyDate\":1623945600000,\"basicsPolicy\":{\"basicsPolicyCompany\":\"基础保单承保公司\",\"basicsPolicyEndDate\":1658505599000,\"basicsPolicyNo\":\"基础保单保单号码\",\"basicsPolicyStartDate\":1626969600000,\"graduateYear\":\"2023\",\"insuredIdvChatNo\":\"WWWWWWWW\",\"insuredSchool\":\"就读学校\",\"linkerChatNo\":\"\",\"linkerRelation\":\"\",\"linkeridentifyNumber\":\"\"},\"beneficiary\":[],\"benefitOrder\":\"\",\"birthday\":983894400000,\"contactPhone\":\"\",\"country\":\"\",\"email\":\"15000000034@163.com\",\"endDate\":1658419200000,\"identifyNumber\":\"110101200103072258\",\"identifyType\":\"51\",\"insuredAddress\":\"\",\"insuredEName\":\"\",\"insuredFlag\":\"1\",\"insuredName\":\"周小军\",\"insuredType\":\"1\",\"itemNo\":1,\"linkerName\":\"\",\"linkerPhone\":\"\",\"mainInsuredFlag\":\"1\",\"mobile\":\"15000000034\",\"occupationCode\":\"A01001\",\"occupationGrade\":\"A\",\"occupationLevel\":\"1\",\"occupationType\":\"A01\",\"planCode\":\"LXSBCYLBX\",\"planName\":\"留学生补充医疗保险(美国版)\",\"relationToAppnt\":\"03\",\"secondIdNum\":\"\",\"secondIdType\":\"\",\"serialNo\":1,\"sex\":\"\",\"socialSecurityFlag\":\"\",\"startDate\":1626969600000}],\"itemKind\":[{\"calculateInd\":\"1\",\"clauseCode\":\"C01177\",\"clauseName\":\"京东安联财产保险有限公司留学医疗补充保险条款\",\"currency\":\"RMB\",\"grossPremium\":1680,\"itemNo\":1,\"kindCode\":\"0422\",\"kindInd\":\"1\",\"kindName\":\"医疗保险金(含门急诊及住院医疗)\",\"remark\":\"\",\"sumInsured\":100000}],\"itemNo\":1,\"rationCount\":1}]},\"main\":{\"endDateStr\":\"2022-07-22 23:59:59\",\"endorseNo\":\"P3100C02109000100001675-001\",\"endorseText\":\"\",\"endorseType\":\"06\",\"giftType\":\"0\",\"groupNo\":\"\",\"inputDate\":1623945600000,\"isSupportFamily\":\"N\",\"jFeeFlag\":\"0\",\"policyNo\":\"P3100C02109000100001675\",\"policyStatus\":\"1\",\"proposalNo\":\"T3100C02109000100001675\",\"renewalFlag\":\"0\",\"signDate\":1623945600000,\"startDateStr\":\"2021-07-23 00:00:00\",\"sumAmount\":100000,\"sumPremium\":1680,\"sumQuantity\":1,\"underWriteEndDate\":1626019200000,\"validDateStr\":\"2021-07-23 00:00:00\"},\"renewal\":{},\"riskInfo\":{\"DestAirport\":\"\",\"FlightDate\":\"\",\"FlightNumber\":\"\",\"FlightTime\":\"\",\"OriginAirport\":\"\",\"arriveDate\":\"\",\"arriveTime\":\"\"},\"sales\":{\"agentCode\":\"AC600002\",\"agentName\":\"非见费出单测试渠道\"}}},\"requestHead\":{\"consumerID\":\"Apis\",\"consumerSeqNo\":\"a5a3214bab664b979f66d63e89227d4b\",\"transactionDate\":1626072102396}}";
JSONObject jsonObject = JSON.parseObject(line);
JSONObject requestBody = jsonObject.getJSONObject("requestBody");
JSONObject policy = requestBody.getJSONObject("policy");
JSONObject coverage = policy.getJSONObject("coverage");
JSONArray itemList = coverage.getJSONArray("itemList");
for (int i=0;i<itemList.size();i++){
JSONObject jsonObject1 = itemList.getJSONObject(i);
JSONArray insuredIdvList = jsonObject1.getJSONArray("insuredIdvList");
for (int j=0;j<insuredIdvList.size();j++){
JSONObject jsonObject2 = insuredIdvList.getJSONObject(j);
System.out.println(jsonObject2.getJSONObject("basicsPolicy"));
}
}
}
输出结果:
{"insuredIdvChatNo":"WWWWWWWW","basicsPolicyCompany":"基础保单承保公司","linkerChatNo":"","basicsPolicyNo":"基础保单保单号码","basicsPolicyStartDate":1626969600000,"linkeridentifyNumber":"","linkerRelation":"","basicsPolicyEndDate":1658505599000,"graduateYear":"2023","insuredSchool":"就读学校"}
推荐一个神器(chrome 插件) json handle
public static void main(String[] args) throws Exception {
String str = "{"requestBody":{"newApplyNo":"E3100C02109000100000388","policy":{"appliClient":[{"birthday":983894400000,"contactPhone":"","email":"fgf@qq.com","faxNumber":"XXXXXXXXXFW","identifyNumber":"110101200103078833","identifyType":"01","insuredAddress":"","insuredEName":"","insuredName":"周军","insuredType":"1","mobile":"13800138000","serialNo":1,"sex":"1"}],"coverage":{"itemList":[{"goodsCode":"LXSBCYLBX","goodsName":"留学生补充医疗保险(美国版)","insuredCount":1,"insuredIdvList":[{"age":20,"amount":100000,"applyDate":1623945600000,"basicsPolicy":{"basicsPolicyCompany":"基础保单承保公司","basicsPolicyEndDate":1658505599000,"basicsPolicyNo":"基础保单保单号码","basicsPolicyStartDate":1626969600000,"graduateYear":"2023","insuredIdvChatNo":"WWWWWWWW","insuredSchool":"就读学校","linkerChatNo":"","linkerRelation":"","linkeridentifyNumber":""},"beneficiary":[],"benefitOrder":"","birthday":983894400000,"contactPhone":"","country":"","email":"15000000034@163.com","endDate":1658419200000,"identifyNumber":"110101200103072258","identifyType":"51","insuredAddress":"","insuredEName":"","insuredFlag":"1","insuredName":"周小军","insuredType":"1","itemNo":1,"linkerName":"","linkerPhone":"","mainInsuredFlag":"1","mobile":"15000000034","occupationCode":"A01001","occupationGrade":"A","occupationLevel":"1","occupationType":"A01","planCode":"LXSBCYLBX","planName":"留学生补充医疗保险(美国版)","relationToAppnt":"03","secondIdNum":"","secondIdType":"","serialNo":1,"sex":"","socialSecurityFlag":"","startDate":1626969600000}],"itemKind":[{"calculateInd":"1","clauseCode":"C01177","clauseName":"京东安联财产保险有限公司留学医疗补充保险条款","currency":"RMB","grossPremium":1680,"itemNo":1,"kindCode":"0422","kindInd":"1","kindName":"医疗保险金(含门急诊及住院医疗)","remark":"","sumInsured":100000}],"itemNo":1,"rationCount":1}]},"main":{"endDateStr":"2022-07-22 23:59:59","endorseNo":"P3100C02109000100001675-001","endorseText":"","endorseType":"06","giftType":"0","groupNo":"","inputDate":1623945600000,"isSupportFamily":"N","jFeeFlag":"0","policyNo":"P3100C02109000100001675","policyStatus":"1","proposalNo":"T3100C02109000100001675","renewalFlag":"0","signDate":1623945600000,"startDateStr":"2021-07-23 00:00:00","sumAmount":100000,"sumPremium":1680,"sumQuantity":1,"underWriteEndDate":1626019200000,"validDateStr":"2021-07-23 00:00:00"},"renewal":{},"riskInfo":{"DestAirport":"","FlightDate":"","FlightNumber":"","FlightTime":"","OriginAirport":"","arriveDate":"","arriveTime":""},"sales":{"agentCode":"AC600002","agentName":"非见费出单测试渠道"}}},"requestHead":{"consumerID":"Apis","consumerSeqNo":"a5a3214bab664b979f66d63e89227d4b","transactionDate":1626072102396}}";
JSON json = JSON.parseObject(str);
JSONObject jsonObject = getByKey(json, "basicsPolicy");
System.out.println(jsonObject);
}
private static JSONObject getByKey(JSON json, String special) {
if (json instanceof JSONObject) {
for (Map.Entry<String, Object> entry : ((JSONObject) json).entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (special.equals(key)) {
return (JSONObject) value;
}
if (value instanceof JSONObject || value instanceof JSONArray) {
return getByKey((JSON) value, special);
}
}
}
if (json instanceof JSONArray) {
for (int i = 0; i < ((JSONArray) json).size(); i++) {
Object value = ((JSONArray) json).get(i);
if (value instanceof JSONObject || value instanceof JSONArray) {
return getByKey((JSON) value, special);
}
}
}
return null;
}