Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Above codes right or wrong??</p> </blockquote> <p>So look at source:</p> <pre><code>{ "results":{ "constituencies":[ ], "members":[ { "constituency_name":"Beckenham", "member_name":"Bob Stewart", "member_party":"Conservative", "member_biography_url":"http://www.parliament.uk/biographies/commons/Bob-Stewart/3919", "member_website":"http://www.bobstewartmp.com/", "uri":"http://findyourmp.parliament.uk/constituencies/beckenham.json" }, { "constituency_name":"Colchester", "member_name":"Sir Bob Russell", "member_party":"Liberal Democrat", "member_biography_url":"http://www.parliament.uk/biographies/commons/Sir-Bob-Russell/35", "member_website":"http://www.bobrussell.org.uk", "uri":"http://findyourmp.parliament.uk/constituencies/colchester.json" }, ] } } </code></pre> <p>Here you have two <code>JSONObject</code>:</p> <ul> <li>First(whole source)</li> <li>results</li> </ul> <p>results contains(in this snippet of code) two <code>JSONArrays</code>:</p> <ul> <li>constituencies(that is empty array)</li> <li>members(it has two childs)</li> </ul> <p>So you need to first fetch whole <code>JSON</code> then results and then you have access to arrays.</p> <pre><code>JSONObject root = new JSONObject(str); // whole source JSONObject results = root.getJSONObject("results"); JSONArray constituenciesArr = results.getJSONArray("constituencies"); JSONArray membersArr = results.getJSONArray("members"); JSONObject child = null; for (int i = 0; i &lt; membersArr.length(); i++) { child = membersArr.getJSONObject(i); String mName = child.getString("member_name"); ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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