开发者

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 re开发者_如何转开发trieve each data from this. Thank you


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();
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜