【发布时间】:2017-04-03 19:12:31
【问题描述】:
我想获取网站上的数据:
try {
URL url = new URL("https://euw.api.riotgames.com/api/lol/" + region + "/v1.4/summoner/by-name/" + summonerN + "?api_key=" + apiCode);
parseJSON(url);
} catch (MalformedURLException e) {
Toast.makeText(getBaseContext(), "Error creating URL",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), "Error reading URL",
Toast.LENGTH_LONG).show();
}
还有函数parseJSON(URL url):
public void parseJSON(URL url) throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
Toast.makeText(getBaseContext(), inputLine,
Toast.LENGTH_LONG).show();
in.close();
}
但它不起作用,只会抛出Exception。
我该如何解决?
【问题讨论】:
-
使用retrofi库,很容易从动态url中获取数据
-
@Akashkumar 改造?
-
在下面找到答案。我提供了