1

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

            }
        });
    }
}

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for you answer,I have now managed to read the whole json objects but need help with displaying the images and the text as listview any idea the best way.
@Mohamed: Great, you can accept this answer by clicking the check sign to the left of it. If you need further help with the json data then please ask a new question on this site.
0

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?

1 Comment

The problem is when parsing passes here:"agentRef": "HF623574000",the program crashes which makes the starting point of the "summary" the main problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.