0

I am receiving data from the server using Volley, but the received data is coming within double quotes.

"{"Meta Data":{"1. Information":"Daily Prices (open, high, low, close) and Volumes","2. Symbol":"INSI","3. Last Refreshed":"2017-11-24","4. Output Size":"Full size","5. Time Zone":"US/Eastern"},"Time Series (Daily)":{"2017-11-24"....}"

I need to parse this information in order to extract the data but I am unable to convert it into JSONObject. I am clueless. On using jsonArray = new JSONArray(response); The debugger says jsonArray is NULL TIA.

Arman Manucharyan
  • 237
  • 1
  • 4
  • 18
jyotirmaya ojha
  • 73
  • 1
  • 13
  • have you tried this https://stackoverflow.com/questions/5245840/how-to-convert-string-to-jsonobject-in-java – joao86 Nov 25 '17 at 17:29
  • or this `JsonObject obj = new JsonParser().parse(jsonString).getAsJsonObject();` – joao86 Nov 25 '17 at 17:30
  • I added compile 'com.googlecode.json-simple:json-simple:1.1' to my gradle and JSONParser started appearing in intellisense but then getAsJsonObject is still not recognised. @joao86 – jyotirmaya ojha Nov 25 '17 at 17:40
  • JsonParser is from org.gson library. – joao86 Nov 25 '17 at 17:47

1 Answers1

1

@jyotirmaya ojha, the JSON string that you shared have JSON Object not JSON Array, so the debugger will always say jsonArr is NULL because JSON Object cannot be casted in JSON Array

Please try this instead

JSONObject jsonObj = new JSONObject(response);
Irfan Anwar
  • 1,878
  • 17
  • 30
  • I am able to access a particular string by its name key, for eg: jsonObj.getString("Time Series (Daily)"). But How can I access the first Key value pair in this string ie. jsonObj.getString("Time Series (Daily)"). Would be easy to parse once I can get values through indices. – jyotirmaya ojha Nov 25 '17 at 18:47