我试图如下构造一个json,
{
"session_token": "f3bb3e20d38d4624930636de074a0df0",
"request": [
"ApproveStatutoryMapping", {
"statutory_mappings": [{
"statutory_mapping_id": 3,
"statutory_provision": "POG ActPOG Act>>State Rule All",
"approval_status": 1,
"rejected_reason": null,
"notification_text": null
}]
}
]
}
以下是我的代码,
private JSONObject frameApproveJson() {
JSONObject rootJson = new JSONObject();
try {
JSONObject innerJobj = new JSONObject();
innerJobj.put("statutory_mapping_id", "3");
innerJobj.put("statutory_provision", "POG ActPOG Act>>State Rule All");
innerJobj.put("approval_status", "1");
innerJobj.put("rejected_reason", null);
innerJobj.put("notification_text", null);
JSONArray innerJarr = new JSONArray();
innerJarr.put("statutory_mappings");
innerJarr.put(innerJobj);
JSONArray inJarr = new JSONArray();
inJarr.put("ApproveStatutoryMapping");
inJarr.put(innerJarr);
rootJson.put("session_token", "806915cf50ab4997b7b135f539fe949b");
rootJson.put("request", inJarr);
} catch (JSONException e) {
e.printStackTrace();
}
return rootJson;
}
问题是我的代码未构建所需的json。我缺少的是什么。在将所有值添加到rootjson对象之后,我什至还返回了root json对象。但是同样的问题仍然存在
innerJarr
应该是对象而不是数组。
更换
JSONArray innerJarr = new JSONArray();
innerJarr.put("statutory_mappings");
innerJarr.put(innerJobj);
经过
JSONObject innerJarr = new JSONObject();
JSONArray innerJarrBis = new JSONArray();
innerJarrBis.put(innerJobj);
innerJarr.put("statutory_mappings", innerJarrBis);
应该解决这个问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句