我试图解析此JSON:解析JSON阵列
[{
"codError": 0,
"msg": "OK"
}, {
"id": 1,
"role": {
"id": 4,
"name": "Super",
"description": "Roling.",
"rights": [],
"superuser": true,
"active": true,
"optimisticLock": 0
},
"now": null,
"points": [],
"firstName": null,
"lastName": null,
"loginName": "admin",
"password": null,
"connected": true,
"active": true,
"optimisticLock": null
},
["U4"]
]
我不能让角色ID和登录名的值,我的代码是在这里:
private static final String TAG_ROLE = "role";
private static final String TAG_ID = "id";
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONArray jsonarr =new JSONArray(jsonStr);
JSONObject jobj=jsonarr.getJSONObject(1);
JSONObject role =jobj.getJSONObject(TAG_ROLE);
String role_id = role.getString(TAG_ID);
} catch (JSONException e) {
e.printStackTrace();
}
调试我应用和字符串role_id没有任何价值,代码的问题是什么?谢谢
同样的问题! http://stackoverflow.com/questions/23405108/parsing-json-with-android – vjdhama
一旦检查TAG_ROLE和TAG_ID,然后使用getInt而不是getString。 –
yes是同一个问题,因为仍然不能正常工作,tag_role和Tag_id都可以 – Igor