我有以下json jsonobject。我可以阅读一些但不是全部属性。如果我打印JSONObj我得到:
JSONObj:
{
"@priority":"50",
"flags":{
"scheduleStatus":"DURING"
},
"@startDate":"2013-10-15T12:30:57.493Z",
"description":"UserReconcile",
"@distributionStrategy":"OFFER",
"name":"UserReconcile",
"itemContext":{
"appName":"MyProcess",
"appInstance":"pvm:0a12iq",
"activityName":"UserReconcile",
"appID":"_-hYCETV8EeOr4-yR8gXd7g",
"activityID":"pvm:001im4"
}
}
我能够获取@ priority,description和其他一些值。我无法获取“ activityID”,这是最后一个密钥。
我的代码确定值是:
priority=jsonObj.getString("@priority");
startDate =jsonObj.getString("@startDate");
workDesc=jsonObj.getString("description");
这失败了:
amxref = jsonObj.getString("activityID");
最佳答案
这是JSON的扩展视图:
{
"@priority": "50",
"flags": {
"scheduleStatus": "DURING"
},
"@startDate": "2013-10-15T12:30:57.493Z",
"description": "UserReconcile",
"@distributionStrategy": "OFFER",
"name": "UserReconcile",
"itemContext": {
"appName": "MyProcess",
"appInstance": "pvm:0a12iq",
"activityName": "UserReconcile",
"appID": "_-hYCETV8EeOr4-yR8gXd7g",
"activityID": "pvm:001im4"
}
}
你能发现问题吗?
是
activityID
不是jsonObj
对象的键。你应该做:
JSONObject itemContext = jsonObj.getJSONObject("itemContext");
String activityID = itemContext.getString("activityID");
关于java - 无法读取所有JSON属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19427533/