我面临一些问题,要从我的json响应中获取价值。我的Json回复如下:
{
"changed": [
"username",
"phone",
"profile_picture",
"public_ind"
],
"failed": []
}
请有人给我一些线索,以便我可以从我的JSON响应中获得价值。
答案 0 :(得分:1)
试试这个:
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArrayChanged = jsonObject.getJSONArray("changed");
String failed = jsonObject.getString("failed");
for(int i=0;i<jsonArrayChanged.length();i++){
String str = jsonArrayChanged.getString(i);
}
答案 1 :(得分:1)
//first parse your root object from json string
JSONObject rootObject = new JSONObject(Sring_data);
//get the json array object
JSONArray changedFields = rootObject.getJSONArray("changed");
//iterate the array object
for (int i = 0; i < changedFields.size(); i++) {
Log.d("", changedFields.getString(i)); //here you will get each array items
}
// parse other json objects other than json array
String failedObj = rootObject.getString("failed");