you see:
json array:
[{"group_id":"20","name":"\u0518\u0500\u011a`"},
{"group_id":"19","name":"\u0518\u0500\u011a`"},
{"group_id":"18","name":"\u0518\u0500\u011a"}]
code:
List<HashMap<String, Object>> dataHashMaps = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> hashMap = new HashMap<String,Object>();
hashMap.put("groupname", jsonArray.getJSONArray(0));
Log.i("jsonobject",jsonArray.getJSONArray(0).toString());
dataHashMaps.add(hashMap);
SimpleAdapter listadapter = new SimpleAdapter(this,dataHashMaps,R.layout.keygrouplist,
new String[]{"name"},
new int[]{R.id.groupname});
listKeyListView.setAdapter(listadapter);
how can i do? it doesn't work?
------解决方案--------------------
JSONArray不能直接拿来用,你得把json解析成一个个的对象,然后再拼接成list
------解决方案--------------------
gson, jackson等先转成object
------解决方案--------------------
// 获取数据列表
for (int i = 0; i < jsonArray.length(); i++) {
String title = jsonArray.getJSONObject(i).getString(
title);
String score = jsonArray.getJSONObject(i).getString(
score);
String pic = jsonArray.getJSONObject(i).getString(
pic);
// 添加到列表中
Map<String, Object> map = new HashMap<String, Object>();
map.put(name, title);
map.put(score, score);
map.put(pic, pic);
dataHashMaps.add(map);
}
你借鉴一下我写的列子