Mohamed
Mohamed

Reputation: 25

Error parsing Json data

I would be gratefull if someone can help,I have been trying to parse the below json string for sometime.My problem is when it reaches a particular position it crashes and says:

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? 

Below is the code used to parse this 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(); 

            }
        });
    }
}

Upvotes: 1

Views: 588

Answers (2)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34014

A line break, as found in the value of the summary property, is not allowed inside a JSON string and has to be escaped as \n. See the JSON spec for details.

Upvotes: 1

djna
djna

Reputation: 55897

When faced with this kind of problem I would trim down the JSON to something small that works and binary chop my way to identify the problem.

Could that 13' abbreviation of 13 foot be the problem?

Upvotes: 0

Related Questions