我已经查看了所有过去的堆栈溢出问题,而我似乎无法弄清楚这一点。Android:从URI获取JSON
我想要做的是给一个uri并从中接收一个JSON。这是我到目前为止的代码:
public void setUpTheJSONs() throws IOException, JSONException, URISyntaxException {
jsonSummonerInfo = getJsonSummonerInfo();
jsonSummonerRankedStats = getJsonRankedStats();
}
public JSONObject getJsonSummonerInfo() throws IOException, JSONException, URISyntaxException {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/kinoscorpia?api_key=my_api_key_here");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if(entity != null){
JSONObject temp = new JSONObject(EntityUtils.toString(entity));
return temp;
} else {
return null;
}
}
}
但是,我从来没有得到回应和响应= httpClient.execute(httpPost)线。
当您在网站中键入uri时,弹出JSON,但不会在代码运行时弹出。
任何帮助?
感谢☺
哪里是你的'getJsonSummonerInfo()'方法执行?如果它在Activity或者Service中,你可能会得到一个NetworkOnMainThreadException异常。检查logcat是否有例外。 – Squonk
你的清单中是否有INTERNET权限? – josephus
我建议你不要发布你的api_key –