I am new JSON android eclipse. I am doing a listview with images similar to the following tutorial: http://www.wingnity.com/blog/android-json-parsing-and-image-loading-tutorial/. The tutorial contains a JSON array that contains the array name.
My JSON array does not contain the array name. My question now is how can I code a JSON Array without the array name:
Below is my JSON code:
[
{
"ID":0,
"Title":"Malokase backs Mabena to shine",
"thumbURL":"http://www.testing.co.za/App_Images/n00001_thumb.jpg",
"imgURL":"http://www.testing.co.za/App_Images/n00001.jpg",
"Story":"Mabena had a rough time with Orlando Pirates, where expectations from the Ghost weighed heavily on him. But at Stars, the pressure has eased up to the extent that he scored on debut against Mamelodi Sundowns in the MTN8. His goal helped Dikwena beat the Brazilians 2-1 to advance to the semifinals, where they will face Kaizer Chiefs.\\n\\n“Ndumiso has always been a good player,” Malokase said. “It was a good thing for him to start with a goal. I think it will boost his confidence and motivate him to do even better for the club going forward.” Mabena will fill the void left by Siphelele Mthembu, who joined Chiefs. Malokase, a former Pirates striker, advised Mthembu on how to deal with the pressure . “He (Mthembu) has been there (at Chiefs),” Malokase said. \\n\\n“He (Mthembu) has been there (at Chiefs),” Malokase said. “He has been at Pirates too. The most important thing is to put his foot on the ground, not to put himself under pressure, but he should do the business when given a chance.” ",
"Date":"2014-08-07T00:00:00"
},
{
"ID":1,
"Title":"New Signings",
"thumbURL":"http://www.testing.co.za/App_Images/n00002_thumb.jpg",
"imgURL":"http://www.testing.co.za/App_Images/n00002.jpg",
"Story":"Dikwena signs 8 new players during Kit Launch.\\n\\n1. Ndumiso Mabena\\n2. Lucky Nguzana\\n3. Marothi Diale\\n4. Rhulani Manzini\\n5. Joseph Banyane\\n6. Isaac Nhlapo\\n7. Letladi Madubanya\\n8. Patrick Kaunda",
"Date":"2014-08-07T00:00:00"
}
]
My code I am trying to parse the JSON is below:
String result = "";
protected Boolean doInBackground(String... urls) {
try {
// ------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray(result);
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Article article = new Article();
article.setTitle(object.getString("Title"));
article.setStory(object.getString("Story"));
article.setThumbURL(object.getString("thumbURL"));
articleList.add(article);
}
return true;
}
// ------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if (result == false)
Toast.makeText(getActivity().getApplicationContext(),
"Unable to fetch data from server", Toast.LENGTH_LONG)
.show();
}
When I run the code the list view is not populated, it then goes in the onPostExecute method.