Skip to content Skip to sidebar Skip to footer

Org.json.jsonexception: Value 10.07526 At 0 Of Type Java.lang.double Cannot Be Converted To Jsonobject

I want to parse coordinates from JSON. My problem is: org.json.JSONException: Value 10.07526 at 0 of type java.lang.Double cannot be converted to JSONObject. Thank you for help. My

Solution 1:

Try like this:

try {
        JSONObject jsonObject = newJSONObject("");
        JSONArray placemarks = jsonObject.optJSONArray("placemarks");

        for(int i = 0; i< placemarks.length(); i++){
            JSONObject marker = placemarks.getJSONObject(i);
            JSONArray coordinates = marker.optJSONArray("coordinates");
            double lat = coordinates.optDouble(0);
            double lng = coordinates.optDouble(1);
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

Solution 2:

because that is not how you should be parsing it, you should be doing this

jsonPart.getJSONArray("coordinates").getDouble(j)

Solution 3:

Another way of handling json is using Gson with POJO classes.

1) Look at that site : Jsonschema2pojo

2) Add gson dependecy : compile 'com.google.code.gson:gson:2.3.1'

3) paste your example json format to website and create POJO class.

4) In your java code :

Gson gson = new GsonBuilder().create();

YourPojoClass pojo=new YourPojoClass();

try {
     pojo=gson.fromJson(yourjsonresponse.toString(),YourPojoClass.class);
    } catch (IOException e) {// handle io errors}

Post a Comment for "Org.json.jsonexception: Value 10.07526 At 0 Of Type Java.lang.double Cannot Be Converted To Jsonobject"