Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid get json array nested in array
    text
    copied!<p>Something like <a href="https://stackoverflow.com/questions/6304460/android-how-to-get-data-from-json-having-array-within-array">this question</a> </p> <p>How to save in variables?</p> <p>But with this json code:</p> <pre><code>{ "restarutant": [ { "name": "Hotel Raja", "photo": "http:\/\/i.imgur.com\/Mzt4u.jpg", "address": "93, 2ndc ross, GDP etx.", "area": "Vylaikaval", "city": "Bangalore", "rating": "4", "cuisines": { "first": "Chinese", "second": "Korean" } }, { "name": "Hotel Raja2", "photo": "http:\/\/i.imgur2.com\/Mzt4u.jpg", "address": "93, 2ndc ross, GDP etx. number2", "area": "Vylaikaval2", "city": "Bangalore2", "rating": "4", "cuisines": { "first": "Chinese2", "second": "Korean2" } } ] } </code></pre> <p>Code:</p> <pre><code>JSONObject json = new JSONObject(thepreviousjson); JSONArray jArray = json.getJSONArray("restaurant"); String name[] = new String[jArray.length()]; String photo[] = new String[jArray.length()]; String address[] = new String[jArray.length()]; String area[] = new String[jArray.length()]; String city[] = new String[jArray.length()]; String rating[] = new String[jArray.length()]; String cuisines[] = new String[jArray.length()]; String first[] = new String[jArray.length()]; String second[] = new String[jArray.length()]; for(int i=0; i&lt;jArray.length(); i++){ JSONObject json_data = jArray.getJSONObject(i); name[i] = json_data.getString("name"); photo[i] = json_data.getString("photo"); address[i] = json_data.getString("address"); area[i] = json_data.getString("area"); city[i] = json_data.getString("city"); rating[i] = json_data.getString("rating"); } </code></pre> <p>The point is to have stored: <code> name[0] = "Hotel Raja"... name[1] = "Hotel Raja2" first[0] = Chinese, second[0] = Korean, first[1] = Chinese2, second[1] = Korean2</code></p> <p>I have tried several combination, but nothing happens, what do I need to modify in my code? thanks </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload