[英]Parsing String Value from Json Object Android
I want to get data from the ApiVk method response.responseString 我想从ApiVk方法response.responseString中获取数据
String jsonStr1 =response.responseString;
JSONArray arr = new JSONArray(jsonStr1);
JSONObject jObj = arr.getJSONObject(0);
String date = jObj.getString("id");
And i'm getting NPE How do I parse the string to get an array of values "id" 而且我正在获取NPE如何解析字符串以获取值数组“ id”
String jsonStr1 = "{\"response\":{\"count\":254,\"items\":[{\"last_name\":\"Екимов\",\"id\":325813465,\"first_name\":\"Артём\"},{\"last_name\":\"Виноградов\",\"id\":448209461,\"first_name\":\"Дэнчик\"},{\"last_name\":\"Κонстантинов\",\"id\":444441827,\"first_name\":\"Κонстантин\"}]}}";
For this json: 对于此json:
{
"response": {
"count": 254,
"items": [{
"last_name": "Екимов",
"id": 23892340,
"first_name": "Артём"
}, {
"last_name": "Екимов",
"id": 23892381,
"first_name": "Артём"
}, {
"last_name": "Екимов",
"id": 23828492,
"first_name": "Артём"
}]
}
}
The analysis to get the id is as follows: 获取ID的分析如下:
try {
JSONObject jsonresponse = jsonResponse.getJSONObject("response");
JSONArray getJsonArray = jsonresponse.getJSONArray("items");
for(int i = 0; i<getJsonArray.length();i++){
JSONObject jsonAux= (JSONObject) jsonArrayItems.get(i);
String id = jsonAux.getString("id");
Log.e("ID = ",id);
}
} catch (JSONException e) {
e.printStackTrace();
}
I hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.