【发布时间】:2013-11-25 01:05:59
【问题描述】:
我试图构建一个以 heroku 服务器作为后端的 android 应用程序。我正在尝试通过 heroku URL 将 JSON 数据作为字符串获取。
这是json字符串的链接
而url的内容是
[{"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"}}]
这是我的代码:
//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;
}
}
当我运行这段代码时,我得到的回报是
“大富翁?!”
所以我假设我遇到了麻烦
response = httpclient.execute(new HttpGet(url));
我从 2 天开始一直在修改代码,但我无法找出问题所在。请帮帮我。
谢谢!
【问题讨论】:
-
请贴出logcat的输出,否则很难帮到你。
-
@CompuChip 你是对的。我错过了 INTERNET 许可。这解决了一切。谢谢!
标签: java android heroku httpclient