0

I am trying to deserialize (parse) this JSON: {"test": "TEST2"}

I am new to Java, so I've searched a lot on Google and I finally found the answer here: https://stackoverflow.com/a/18998203/8524395

So, I am trying to deserialize my JSON like that:

JSONObject obj = new JSONObject("{\"test\": \"TEST2\"}");
String testValue = obj.getJSONObject("test").toString();

But I am getting the error: JSONObject obj = new JSONObject("{\"test\": \"TEST2\"}"); String pageName = obj.getJSONObject("test").toString();

Any help would be appreciated.

Thanks!

usamember
  • 468
  • 2
  • 5
  • 15

1 Answers1

0

You should get a string not another object:

String testValue = obj.getString("test");

In other word, test is a key that maps to a string of value TEST2.

NiVeR
  • 9,644
  • 4
  • 30
  • 35