Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the JSONArray that's already in a JSONArray
    text
    copied!<p>I can't seem too get the second layer in the JSON Array. What I want is, to get all the names from the Categories, and then I want to sent the "forums id" trough a intent to an different Activity.<br> If it helps, I followed this <a href="http://www.androidhive.info/2012/01/android-json-parsing-tutorial/" rel="nofollow">tutorial</a> and I'm getting my JSON array from <a href="http://api.facepun.ch/?&amp;action=getforums" rel="nofollow">here</a> </p> <p><strong>Part of JSON Array</strong></p> <pre><code>{ "categories": [{ "name": "Facepunch", "forums": [{ "id": 6, "name": "General Discussion", "viewing": 217 }, { "id": 60, "name": "Fast Threads", "viewing": 188 }, { "id": 64, "name": "Videos And Flash Movies and That Kind Of Crap", "viewing": 239 }, { "id": 403, "name": "Mass Debate", "viewing": 9 }, { "id": 396, "name": "Sensationalist Headlines", "viewing": 455 }, { "id": 51, "name": "In The News Node", "viewing": 100 }] }] } </code></pre> <p>Part of my code</p> <pre><code>try { // Getting Array of Contacts categories = json.getJSONArray(TAG_CATEGORIES); forums = json.getJSONArray(TAG_FORUMS); // looping through All categories for(int i = 0; i &lt; categories.length(); i++){ JSONObject c = categories.getJSONObject(i); // Storing each json item in variable String CatName = c.getString(TAG_CATName); // Phone number is agin JSON Object JSONObject All_forums = forums.getJSONObject(i); String forum_id = All_forums.getString(TAG_FORUMS_ID); String forum_name = All_forums.getString(TAG_FORUMS_NAME); // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // adding each child node to HashMap key =&gt; value map.put(TAG_CATName, CatName); map.put(TAG_FORUMS, forum_name); // adding HashList to ArrayList contactList.add(map); } } catch (JSONException e) { e.printStackTrace(); } </code></pre>
 

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