Json对象:
{"SessionID":"ae231c4b-6c69-4dec-8d52-be0786cdcdd8",
"RequestUniqueID":"34356566545677",
"ReportCode":"01",
"Condition":"{\"ReferenceNumber\":\"500\"}",
"MethodName":"TopupGetReport"}
我想解析这个对象;我该怎么做?
答案 0 :(得分:1)
String response = "{\"SessionID\":\"ae231c4b-6c69-4dec-8d52-be0786cdcdd8\",\"RequestUniqueID\":\"34356566545677\",\"ReportCode\":\"01\",\"Condition\":{\"ReferenceNumber\":\"500\"},\"MethodName\":\"TopupGetReport\"}";
try {
JSONObject obj = new JSONObject(response);
String sessionId = obj.getString("SessionID");
String rqstUniqueId = obj.getString("RequestUniqueID");
String reportCode = obj.getString("ReportCode");
String methodName = obj.getString("MethodName");
JSONObject condition = obj.getJSONObject("Condition");
String referenceNumber = condition.getString("ReferenceNumber");
System.out.println(sessionId + ", " + rqstUniqueId + ", " + reportCode + ", " + methodName + ", " + referenceNumber);
} catch (JSONException e) {
e.printStackTrace();
}
产生:
ae231c4b-6c69-4dec-8d52-be0786cdcdd8,34356566545677,01,TopupGetReport,500
注意:我认为定义Condition
数据的括号周围的一些额外引号只是一个错误,可能是从某些测试代码复制到您的问题中。我删除了它们(请参阅我的response
字符串)。