JSON解析到ListView Android [英] JSON Parsing to ListView Android
本文介绍了JSON解析到ListView Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从JSON解析到Android中的Listview时遇到问题.这是JSON数据的示例:
I have a problem to parsing from JSON to Listview in Android. This is an example of data from JSON :
[{
"area": "Kebon Jeruk",
"city": "Jakarta"
}, {
"area": "Puri",
"city": "Jakarta"
}, {
"area": "Grogol",
"city": "Jakarta"
}]
,我想使ListView像这样:
and I want to make ListView like this :
非常感谢您.
推荐答案
JSONArray arr = new JSONArray(yourJSONresponse);
List<String> list = new ArrayList<String>();
for(int i = 0; i < arr.length(); i++){
String info = arr.getJSONObject(i).getString("area") + arr.getJSONObject(i).getString("city");
list.add(info);
}
然后将列表转换为字符串数组,然后使用适配器像下面这样填充ListView
:
And then just turn the List into an Array of Strings, and use an adapter to fill the ListView
like so:
ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,StringArray);
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
这篇关于JSON解析到ListView Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文