I am newbie in android programmimng and i am trying to create an app for my food blog.I found this json paring tutorial on internet. when i put my yql query into the code,it gives me an error " no value for json". when i tried to fix them,i found that error is in my jsonobject varible which requires a string "json" like this...
how can i fix this error... help me
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.listview_main);
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
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("Welcome to Food-n-moreblog App");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
arraylist = new ArrayList<HashMap<String, String>>();
// YQL JSON URL
String url = "https://query.yahooapis.com/v1/public/yql?q=SELECT%20title%20FROM%20atom%20WHERE%20url%3D%22http%3A%2F%2Ffood-n-moreblog.blogspot.com%2Ffeeds%2Fposts%2Fdefault%22%20LIMIT%205%20&format=json&callback=";
try {
// Retrive JSON Objects from the given URL in JSONfunctions.class
JSONObject json_data = JSONfunctions.getJSONfromURL(url);
JSONObject json_query = json_data.getJSONObject("title");
JSONObject json_results = json_query.getJSONObject("results");
JSONObject json_json_result = json_results
.getJSONObject("entry");
JSONArray json_result = json_json_result.getJSONArray("items");
for (int i = 0; i < json_result.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject c = json_result.getJSONObject(i);
JSONObject vo = c.getJSONObject("entry");
map.put("title", vo.optString("title"));
/* map.put("description", vo.optString("description"));
JSONObject il = vo.getJSONObject("imageLinks");
map.put("thumbnail", il.optString("thumbnail"));*/
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);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
Here is my Json
{
"query": {
"count": 5,
"created": "2015-12-16T10:00:40Z",
"lang": "en-US",
"results": {
"entry": [
{
"title": {
"type": "text",
"content": "Recipe : home-made Curd | how to make yoghurt at home"
}
},
{
"title": {
"type": "text",
"content": "Recipe: Classic Vanilla Icecream | how to make eggless vanilla icecream at home"
}
},
{
"title": {
"type": "text",
"content": "Recipe : Matar Mushroom in white gravy | Peas mushroom in white sauce"
}
},
{
"title": {
"type": "text",
"content": "Recipe : Mississippi Mud and Chocolate Frappe`"
}
},
{
"title": {
"type": "text",
"content": "Recipe : Moong Dal Khichdi | how to make yellow gujrati khichadi"
}
}
]
}
}
}