Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Parsing for Android - nested items?
    text
    copied!<p>I have used this site for years, but never have posted. I am stumped and hope someone might be able to help me.</p> <p>I am using very similar code to what Slicekick posted here <a href="https://stackoverflow.com/questions/6884443/json-parsing-app-no-data/8753557#8753557">JSON parsing app &quot;no data&quot;?</a>, but can not seem to figure out how to parse this JSON file. I have edited his JSON info to reflect the exact format I am trying to parse to save space/time. How do I parse the "Results" so I can query "Name" and "Type"? Like his problem with "Similar" and "Info", how do I parse "Info" and "Results" in the file below?</p> <p>Here is an example of a JSON file edited in the exact format I am using:</p> <pre><code>{ "head": { "title": "Music", "status": "200" }, "Info": [ { "Name": "Mos Def", "Type": "music", "Results": [ { "Name": "Talib Kweli", "Type": "music" }, { "Name": "Black Star", "Type": "music" }, { "Name": "Little Brother", "Type": "music" } ] }, { "Name": "Mos Def", "Type": "Vehicles", "Results": [ { "Name": "Chevy", "Type": "Car" }, { "Name": "Ford", "Type": "Car" }, { "Name": "Pontiac", "Type": "Car" } ] } ] } </code></pre> <p>The part of my code that may be of interest is:</p> <p>... I do a httpget ... that gets built into a StringBuilder ... creates a JSONObject with the results of StringBuilder</p> <pre><code> jArray = new JSONObject(result); </code></pre> <p>... then returns that</p> <p>Then onto...</p> <pre><code> JSONArray Info = json.optJSONArray("Info"); System.out.println("HERE IS INFO: "); System.out.println(Info); //System.out.println("HERE IS RESULTS: "); //System.out.println(Results); </code></pre> <p>And basically here is where I am stumped. I put in print messages to try to narrow the issue down.</p> <p>Parsing "Info" allows me to search: "Name": "Mos Def" "Type": "music" -and- "Name": "Mos Def" "Type": "Vehicles"</p> <p>Replacing the search of "Info" with "Results" gives me no data. (Not found)</p> <p>Any ideas?</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