我会gratefull如果有人能帮忙,我一直在试图解析为sometime.My问题下面的JSON字符串,当它到达崩溃的特定位置,并说:错误解析JSON数据
Error parsing data org.json.JSONException: Value {"summary":"A bay fronted character semi-detached home. Offering two separate reception rooms and double glazing. Three bedrooms, 13' kitchen with door offering access to the rear.What am i doing wrong?
下面是用来解析此JSON
public class LocationSearch extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listplaceholder);
ArrayList<HashMap<String, String>> mylist =
new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL("http://api.mycomp.co.uk
/api/propertyDetails?propertyId=12345&apiApplication=BRIGHTSPARKS");
try{
JSONArray location = json.getJSONArray("property");
for(inti=0i<location.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = location.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", "property name:" + e.getString("identifier"));
//map.put("name", "visible: " + e.getString("visible"));
//map.put("name", "price: " + e.getString("price"));
map.put("name", "summary: " + e.getString("summary"));
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[] { "name", "visible","price","summary" },
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(LocationSearch.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
}
非常感谢您的回答,我现在设法读取整个json对象,但需要显示图像和文本作为列表查看任何想法的最佳方式的帮助。 – Mohamed 2011-12-22 22:01:21
@穆罕默德:太好了,您可以通过点击左边的勾号来接受答案。如果你需要JSON数据的进一步帮助,那么请在这个网站上提出一个新问题。 – 2011-12-22 22:31:58
你赢得了我的投票,非常感谢。 – Mohamed 2011-12-22 23:43:51