I have used this site for years, but never have posted. I am stumped and hope someone might be able to help me.
I am using very similar code to what Slicekick posted here JSON parsing app "no data"?, 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?
Here is an example of a JSON file edited in the exact format I am using:
{
"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"
}
]
}
]
}
The part of my code that may be of interest is:
... I do a httpget ... that gets built into a StringBuilder ... creates a JSONObject with the results of StringBuilder
jArray = new JSONObject(result);
... then returns that
Then onto...
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);
And basically here is where I am stumped. I put in print messages to try to narrow the issue down.
Parsing "Info" allows me to search: "Name": "Mos Def" "Type": "music" -and- "Name": "Mos Def" "Type": "Vehicles"
Replacing the search of "Info" with "Results" gives me no data. (Not found)
Any ideas?