I have a string called "response" like this:
{"test": {
"id": 179512,
"name": "Test",
"IconId": 606,
"revisionDate": 139844341200,
"Level": 20
}}
I want to save id value to a variable. How can i do it?
JSONObject jsonObj = new JSONObject(response);
jsonObj.getInt("id");
This dont work.
Try this..
JSONObject jsonObj = new JSONObject(response);
JSONObject test_jsonObj = jsonObj.getJSONObject("test");
int id = test_jsonObj.getInt("id");
You have to do:
JSONObject jsonObj = new JSONOBject(response);
JSONObject nestedObj = jsonObj.getJSONObject("test");
int id = nestedObj.getInt("id");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.