-1

i have a JSON:

String jsonString = "{"Tech":"{id :[""],techInside :["Java","C++"]}","id1":"","state":""}";

So i need the value of techInside. How do i access that > I have tried:

JSONObject obj = new JSONObject(jsonString);
string techInside = obj.getJSONObject("Tech").getJSONArray("techInside");

But it gave me an exception:org.json.JSONException: Expected a ',' or '}' at 17.
Tried Many other ways but spent a lot of time on it. Need some suggestions please.

Note: i am using escape characters in the string.So please ignore about the escaping characters in the jsonString

user7637864
  • 237
  • 3
  • 5
  • 15
  • Have you looked at this? http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java?rq=1 – lakeIn231 Mar 13 '17 at 17:49
  • 3
    Please provide a [mcve]. As it is your code isn't even compilable, e.g. `string techInside` probably should be `String techInside` but besides that how do you expect to be able to cast the return value of `getJSONArray()` to `String`? – Thomas Mar 13 '17 at 17:50
  • Your JSON is invalid, and `getJSONArray()` doesn't return a "string" (or even a `String`), it returns a `JSONArray`. – azurefrog Mar 13 '17 at 17:54

2 Answers2

1

Your JSON is invalid. There should be no "" around objects ({}).

Try with this JSON-String:

String jsonString = "{\"Tech\":{\"id\":[\"\"], \"techInside\":[\"Java\", \"C++\"]}, \"id1\":\"\", \"state\":\"\"}"

Or without escaping

{"Tech":{"id":[""], "techInside":["Java", "C++"]}, "id1":"", "state":""}
SilverNak
  • 3,283
  • 4
  • 28
  • 44
  • Oh. Thanks for that. I just blindly used some online tool to validate the JSON. It gave me a green so didnt even had a look at it again. Let me try reformatting the JSON. Thanks. – user7637864 Mar 13 '17 at 17:56
-1

I think the kind of json you are looking for is

{"Tech": {"id" : "", "techInside" : ["Java","C++"]},"id1":"","state":""}

Not sure, what your requirement is.

Ravi Sanker
  • 84
  • 1
  • 5