i have created a code to parse the data(job listings) from my website and should make it displayed in Android app, i have used JSON parser to do this task, So installed JSON api in the website, project is bug free, but when i run i'm not getting the output... i think i have gone wrong in defining the JSONobject. Here's my code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.httpex);
httpStuff = (TextView) findViewById(R.id.tvHttp);
client = new DefaultHttpClient();
new Read().execute("posts");
}
public JSONObject lastTweet(String string) throws ClientProtocolException, IOException, JSONException {
StringBuilder url = new StringBuilder(URL);
url.append(string);
HttpGet get = new HttpGet (url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if (status==200){
HttpEntity e=r.getEntity();
String data = EntityUtils.toString(e);
JSONArray Categories = new JSONArray(data);
JSONObject Featured = Categories.getJSONObject(1);
return Featured;
}
else
{
Toast.makeText(HttpExample.this, "error", Toast.LENGTH_LONG);
return null;
}
}
public class Read extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try{
json = lastTweet("mybringback");
return json.getString(params[0]);
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
catch (JSONException e){
e.printStackTrace();
}
return null;
}
This code was done by following some tutorial where that was to parse the twitter content, so i edited the url and JSONobject by mine. so please help me to correct the errors.