0

My JSONObject:

JSONObject callback = {"message": "message here", "response": "response here"}

I want get the response here from json's respone string. I've tried the following:

JSONObject response = callback.getJSONObject("response");
String message = next.getString("response");

I get the errot like String and JSONObjet conversion problems.

Zala Janaksinh
  • 2,929
  • 5
  • 32
  • 58
sark9012
  • 5,485
  • 18
  • 61
  • 99
  • possible duplicate of [Sending and Parsing JSON in Android](http://stackoverflow.com/questions/2818697/sending-and-parsing-json-in-android) – Blacklight Nov 06 '14 at 10:15
  • I don't agree, I'm not looking to use a third party library. I just want to get access to that one variable the way I am doing it with JSONObject. – sark9012 Nov 06 '14 at 10:18
  • "response" holds a JSONObject or String? – Top Cat Nov 06 '14 at 10:18
  • @sark9012 Well, the answers are not only about 3rd party libraries, there are also a lot of tutorials and other links that show the proper use of methods on `JSONObject`. – Blacklight Nov 06 '14 at 10:22

2 Answers2

1

JSONObject callback = {"message": "message here", "response": "response here"}

you need to access response value like below code

String response = callback.getString("response");
Kirtan
  • 1,782
  • 1
  • 13
  • 35
1

Try out as below:

JSONObject callback = {"message": "message here", "response": "response here"}

String response = callback.getString("response");
String message = callback.getString("message");
GrIsHu
  • 29,068
  • 10
  • 64
  • 102