【发布时间】:2016-04-20 14:49:41
【问题描述】:
从维基百科获取城市信息,并在 Android APP 上展示。
但是,每次我尝试将数据转换为 JSON 时,都会引发异常
url = new URL("https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Threadless&rvprop=content&format=json&rvsection=0");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
String line ="";
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
sb = new StringBuilder();
while ((line = reader.readLine()) != null){
sb.append(line);
}
JSONObject city;
JSONArray jsondata = new JSONArray(sb.toString());
city = jsondata.getJSONObject(0);
【问题讨论】:
-
这与城市无关,缺少例外。
标签: java android api rest wikipedia-api