简体   繁体   中英

How to retrieve JSON value in Android?

How can i retrieve this JSON value in int

{
"success": 1,
"message": "Product successfully retrieved."
}

I used this code but it doesn't work

JSONObject obj = response.getJSONObject("success");
int a = obj.getInt("success");
Log.e("YASH", String.valueOf(a));

JSONObject msg = response.getJSONObject("message");
String m = msg.getString("message");
Log.e("YASH", m);

IF you have the JSONObject response, you don't need the response.getJSONObject. You just need response.getInt("success") and response.getString("message")

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM