它正在連接並從json數組中提取數據。它添加了兩個listview項目但沒有顯示任何文本?爲什麼數據不會顯示在我的列表視圖中?
JSON陣列 { 「比賽」:[{ 「標題」: 「我的標題」, 「聯繫方式」: 「我的聯繫人」, 「說明」: 「我的描述」, 「城市」: 「我的城市」, 「國家」:「堪薩斯州」,「類別」:「輪盤」,{「標題」:「我的標題」,「聯繫人」:「我的聯繫人」,「描述」:「我的描述」,「城市」我的城市」, 「國家」: 「康涅狄格」, 「類別」: 「三張牌」}]}
我的一些在Java代碼...
JSONObject json = JSONfunctions.getJSONfromURL("http://kleinefrosch.com/retrieve.php");
try{
JSONArray tourneys = json.getJSONArray("tournaments");
for(int i=0;i<tourneys.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = tourneys.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Title:" , e.getString("Title"));
map.put("Contact:" , e.getString("Contact"));
map.put("Description:" , e.getString("Description"));
map.put("City:" , e.getString("City"));
map.put("State:" , e.getString("State"));
map.put("Country:" , e.getString("Country"));
map.put("Category:" , e.getString("Category"));
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main,
new String[] { "Title","Contact","Description","City","State","Country","Category" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(JsonActivity.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
}
更新爲什麼這個傢伙工作和我的不是?我們使用相同的示例代碼http://stackoverflow.com/questions/7155322/parse-json-data-into-listview – user1411823