akkk
akkk

Reputation: 1467

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);

Upvotes: 1

Views: 46

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93551

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

Upvotes: 3

Related Questions