Java获取嵌套的json串里的数据

{
“requestId”: “SMELP_DATA_CUSTOMS_8062a1b4-a954-4fd1-8ded-40fdf7594296”,
“responseData”: {
“loadType”: “2–2”,
“records”: [
{
“erMsg”: “'银行卡号’卡BIN校验未通过”,
“seqNo”: “0”,
“cardType”: “”,
“authResult”: “”,
“erCode”: “E000001”,
“bankName”: “”
}
],
“detailError”: null,
“responseMessage”: “接口调用成功!”,
“requestNo”: “123”,
“transNo”: null,
“dataSource”: null,
“responseCode”: “000000”
},
“responseMessage”: “请求成功”,
“responseCode”: “000000”
}

例如获取erMsg里的信息:

      //result是调用接口之后返回的String类型的json串

       JSONObject obj = JSONObject.parseObject(result);

       JSONObject responseData = (JSONObject) obj.get("responseData");
       JSONArray records = (JSONArray) responseData.get("records");
       JSONObject erMsg1 =  (JSONObject) records.get(0);            
       String erMsg = erMsg1.getString("erMsg");

例如获取responseMessage里的信息:

        JSONObject obj = JSONObject.parseObject(result);
        String msg = obj.getString("responseMessage");

你可能感兴趣的:(java)