0

I have the following json ,i am facing issue with creating jsonobject for this.Please let me know how to create a jsonobject with nested levels.

{
    "menuConf": {
        "class": "menu horizontal dropdown",
        "caption": "",
        "id": "mainMenu",
        "container": "div",
        "contClass": "navigation main left",
        "helper": "span",
        "items": [
            {
                "caption": "a",
                "class": "orangesec",
                "link": "#",
                "id": "subMenu_1",
                "helper": "span",
                "items": [
                    {
                        "caption": "b",
                        "link": "#b"
                    },
                    {
                        "caption": "b",
                        "link": "#b"
                    },
                    {
                        "caption": "Blbogs",
                        "link": "#b"
                    },
                    {
                        "caption": "b",
                        "link": "#b"
                    }
                ]
            }
        ]
    }
}

1 Answer 1

1

What's wrong with the JSONObject(String) constructor? Just store your JSON text in a string and use it - it should handle nested objects just fine:

String json = "{...}";

try {
    JSONObject o = new JSONObject(json);

    // Print out the JSON text with a 4-space indentation
    System.out.println(o.toString(4));
} catch (JSONException e) {
    e.printStackTrace();
}
Sign up to request clarification or add additional context in comments.

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.