0

I have the following JSON string:

{"widget":{"order":{"fizz":["23", "55"],"setting":"always"}},"resp":"ok"}

And the following Java code:

try {
    JSONObject json = getTheAboveStringAsJSON();
    order = json.getJSONObject("order");
} catch(JSONException e) {
    throw new RuntimeExcept(e.getMessage());
}

Giving me the following exception:

JSONObject["order"] not found.
java.lang.RuntimeException: JSONObject["order"] not found.

What's going on here? Why the exception? What can I do to fix it? Thanks in advance!

1
  • 2
    coz order is a level down from the top of the object. e.g. $json->widget->order, not $json->order. Commented Mar 11, 2013 at 18:45

2 Answers 2

3

Your structure is

{
    "widget":{
        "order":{
            "fizz":["23", "55"],
            "setting":"always"
         }
     },
     "resp":"ok"
}

So you need to first access "widget", and then "order" within the widget

order = json.getJSONObject("widget").getJSONObject("order")
Sign up to request clarification or add additional context in comments.

Comments

0

what ever the json data returning by getTheAboveStringAsJSON() method there is no data with

order key

json.getJSONObject("widget").getJsonObject("order");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.