【发布时间】:2015-07-24 12:24:12
【问题描述】:
我想使用从这个链接返回的 json 编码数组: http://sids.roundone.asia/suggest.json?data=soft 作为 android 应用程序中的建议。
(我在 php 文件中使用了 json_encode($arr) 函数,我将其作为上述链接的响应返回)
我在用 java 读取此响应并将其存储在 ArrayList 中时遇到问题。
我的代码是:
try {
String temp=sName.replace(" ", "%20");
URL js = new URL("https://sids.roundone.asia/suggest.json?data="+temp);
URLConnection jc = js.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
JSONObject jsonResponse = new JSONObject(line);
JSONArray jsonArray = jsonResponse.getJSONArray("results");
for(int i = 0; i < jsonResponse.length(); i++){
JSONObject r = jsonArray.getJSONObject(i);
ListData.add(new SuggestGetSet(jsonResponse.get(String.vlaueOf(iss)));
}
}
【问题讨论】: