测试JSON串:
{ "package": { "additionInfo": { "errorCode": "0", "errorMsg": "Success", "receiverTradeNum": "" }, "body": [ { "medicalNum": "15XXXXXX", "queryDate": "YYYYMMDD", "name": "XXX", "authorizationNum": "xxxxx", "pageNum": "1" } ] } }
目的:获取medicalNum的值
实现:
JSONObject packageJsonObject = jsonObj.getJSONObject("package");// 定位到package json对象 JSONArray bodyJsonArray = packageJsonObject.getJSONArray("body");//采用getJSONArray方法, 定位到body json集合 JSONObject targetJsonObject = bodyJsonArray.getJSONObject(0);// 定位到目标json对象 final String medicalNum = targetJsonObject.getString("medicalNum");// 就诊流水号 System.out.println("----------------------"+medicalNum+"----------------------");
原文链接:https://blog.csdn.net/Alex19961223/article/details/91955116