I manage to retrieve Json content from the URL: http://twitter.com/statuses/public_timeline.json Which provide just tweets. Now I want to retrieve another JSON array from another URL, which has the follwoing format:
{
"contacts": [
{
"id": "c200",
"name": "Ravi Tamada",
"email": "ravi@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
},
{
"id": "c201",
"name": "Johnny Depp",
"email": "johnny_depp@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
},
.
.
}
The diference as you can verify is that the one JSON array has a name and the second not. The code that I was used for the tweet retrieving, was the following one:
private class LoadListTask extends AsyncTask<Void, Tweet, Void> {
private final ProgressDialog pd = new ProgressDialog(TweetTestActivity.this);
// can use UI thread here
@SuppressWarnings("unchecked")
protected void onPreExecute() {
((ArrayAdapter<String>)getListAdapter()).clear();
this.pd.setMessage("Loading List...");
this.pd.show();
}
protected Void doInBackground(Void... ars) {
// TODO 4 new activity with custom adapter to show schedules
try {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://twitter.com/statuses/public_timeline.json");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
JSONArray ja = new JSONArray(client.execute(get, responseHandler));
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
publishProgress(new Tweet(jo.getString("id_str"),jo.getString("text")));
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@SuppressWarnings("unchecked")
protected void onProgressUpdate(Tweet... progress) {
((ArrayAdapter<Tweet>)getListAdapter()).add(progress[0]);
}
protected void onPostExecute(Void result) {
pd.dismiss();
}
}
Question: What changes should i perform to retrieve the contacts array? Because when i just change the id_str to gender(and the URL of course) i take an error which says: org.json.JSONException: No value for gender.