2011-12-20 108 views
1

我会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(); 

      } 
     }); 
    } 
} 

回答

1

在JSON字符串中不允许出现换行符,如summary属性的值中所示,并且必须转义为\n。详情请参阅JSON spec

+0

非常感谢您的回答,我现在设法读取整个json对象,但需要显示图像和文本作为列表查看任何想法的最佳方式的帮助。 – Mohamed 2011-12-22 22:01:21

+0

@穆罕默德:太好了,您可以通过点击左边的勾号来接受答案。如果你需要JSON数据的进一步帮助,那么请在这个网站上提出一个新问题。 – 2011-12-22 22:31:58

+0

你赢得了我的投票,非常感谢。 – Mohamed 2011-12-22 23:43:51

0

当面对这样的问题,我会在JSON减磅的东西小,工程和二进制砍我的方式,以确定该问题的代码。

难道13英尺的13英尺的缩写是问题吗?

+0

问题是当解析在这里传递时:“agentRef”:“HF623574000”,程序崩溃,这使得“摘要”的出发点成为主要问题。 – Mohamed 2011-12-20 16:03:39