2

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

Caspar Harmer
  • 8,097
  • 2
  • 42
  • 39
Jyosna
  • 4,436
  • 13
  • 60
  • 93

2 Answers2

2

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.

Community
  • 1
  • 1
nahwarang
  • 654
  • 5
  • 9
  • ya but i want to know how to retrieve in my abdroid activity page. please give me that answer – Jyosna Jun 10 '11 at 09:46
2

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();
    }
Caspar Harmer
  • 8,097
  • 2
  • 42
  • 39