I want to work with the json below in andoroid, but I am getting an error in my app.I will be working extensively with the yummly api but the data i need resides in the matches array, but I am not sure what is the problem. I have also attahed my json code snippet
{
` "attribution":{`
"html":"<a href='http://www.yummly.com/recipes/onion-soup'>onion soup recipes</a> search powered by <img alt='Yummly' src='http://static.yummly.com/api-logo.png'/>",
"url":"http://www.yummly.com/recipes/onion-soup",
"text":"onion soup recipes: search powered by Yummly",
"logo":"http://static.yummly.com/api-logo.png"
},
"totalMatchCount":41710,
"facetCounts":{
},
"matches":[
{
"attributes":{
"course":[
"Soups"
]
},
"flavors":{
"salty":0.16666666666666666,
"sour":0.16666666666666666,
"sweet":0.16666666666666666,
"bitter":0.16666666666666666,
"meaty":0.16666666666666666,
"piquant":0.0
},
"rating":4,
"id":"Miyabi-Japanese-Onion-Soup-Food_com-111654",
"smallImageUrls":[
"http://i.yummly.com/Miyabi-Japanese-Onion-Soup-Food_com-111654-204787.s.jpg"
],
"sourceDisplayName":"Food.com",
"totalTimeInSeconds":2100.0,
"ingredients":[
"carrot",
"garlic cloves",
"chicken broth",
"beef broth",
"onions",
"onions",
"mushroom",
"green onion"
],
"recipeName":"Miyabi Japanese Onion Soup"
},
{
"attributes":{
"course":[
"Soups"
],
"cuisine":[
"French"
]
},
"flavors":{
"salty":0.6666666666666666,
"sour":0.3333333333333333,
"sweet":0.6666666666666666,
"bitter":0.3333333333333333,
"meaty":0.3333333333333333,
"piquant":0.0
},
"rating":5,
"id":"French-onion-soup-348995",
"smallImageUrls":[
"http://i.yummly.com/French-onion-soup-348995-313707.s.jpg"
],
"sourceDisplayName":"Every Day with Rachael Ray",
"totalTimeInSeconds":2100.0,
"ingredients":[
"swiss cheese",
"dry red wine",
"sweet onions",
"beef broth",
"croutons"
],
"recipeName":"French Onion Soup"
}
],
"criteria":{
"requirePictures":false,
"excludedIngredients":[
],
"allowedIngredients":[
],
"terms":[
"onion",
"soup"
],
"facetFields":[
],
"resultsToSkip":1,
"maxResults":0
}
}
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(MainActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Android JSON Parse Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL(yummlyurl);
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("matches");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put("Recipe Name", jsonobject.getString("recipeName"));
map.put("Ingredients", "Hello");
map.put("Id", "Hello");
map.put("flag", "Hello");
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(MainActivity.this, arraylist);
// Set the adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}