Jyosna
Jyosna

Reputation: 4446

android how to get data from json having array within array

I have an application where i want to fetch data from local server. like

{
    "restarutant":{
    "name":"Hotel Raja",
    "photo":"http:\/\/i.imgur.com\/Mzt4u.jpg",
    "address":"93, 2ndc ross, GDP etx.",
    "area":"Vylaikaval",
    "city":"Bangalore",
    "location":["13.005621","77.577531"],
    "phone":["9986377561","08023467969"],
    "rating":"4",
    "cuisines":["Chinese","Korean"],
    "attributes":["smoking","parking","delivery"]
    }
}

means array within an array please anybody tell me how i retrieve each data from this. Thank you

Upvotes: 2

Views: 4586

Answers (2)

nahwarang
nahwarang

Reputation: 653

Check out the manual example using the Tokenizer or use your own implementation.

Also read this post: Sending and Parsing JSON Objects answers your question.

Upvotes: 2

Caspar Harmer
Caspar Harmer

Reputation: 8117

Try this code:

        String str_json = "your json string from query";

    try {
        JSONObject topobj = new JSONObject(str_json);
        JSONObject innerobj = topobj.getJSONObject("restarutant");

        String name = innerobj.getString("name");
        String photo = innerobj.getString("photo");
        JSONArray cuisines = innerobj.getJSONArray("cuisines");
        //etc etc...

    } catch (JSONException e) {
        e.printStackTrace();
    }

Upvotes: 2

Related Questions