I was trying to build an android app with a heroku server as the backend. I am trying to get JSON data as string through a heroku URL.
Here's the link to the json string
and the contents of the url is
[{"peep":{"age":null,"created_at":"2013-11-23T08:58:09Z","id":1,"name":null,"updated_at":"2013-11-23T08:58:09Z"}},{"peep":{"age":null,"created_at":"2013-11-23T08:59:30Z","id":2,"name":null,"updated_at":"2013-11-23T08:59:30Z"}}]
Here's my code:
//imports go here
public class JSONParser
{
public String getJSONFromUrl(String url)
{
InputStream inpstr = null;
String result = "";
HttpResponse response = null;
// HTTP
try ,
{
HttpClient httpclient = new DefaultHttpClient();
try
{
response = httpclient.execute(new HttpGet(url));
}
catch(Exception e)
{
return "dafuq?!";
}
HttpEntity entity = response.getEntity();
inpstr = entity.getContent();
}
catch(Exception e)
{
return "SHIT!";
}
// Code to get string from input stream
return result;
}
}
When I run this code, The return I get is
"dafuq?!"
So I'm assuming I have trouble with
response = httpclient.execute(new HttpGet(url));
I've been tinkering with the code from 2 days and I haven't been able to figure out what's wrong. Please help me out.
Thanks!