2

model:

public class Geometry { public String type; public List<Position> coordinatesRoute; public double[] coordinatesPoint; method for recover jsonObjet JSONObject objectResponse = new JSONObject(res); JSONArray JarrayFeatures = objectResponse.getJSONArray("features"); for (int i = 0; i < JarrayFeatures.length(); i++) { JSONObject jsonObjFeatures = JarrayFeatures.getJSONObject(i); Log.e("jsonObjFeatures:", " " + jsonObjFeatures); //geoFeatures.setType((String) jsonObjFeatures.get("type")); features.setType((String) jsonObjFeatures.get("type")); JSONObject objectGeometry = jsonObjFeatures.getJSONObject("geometry"); geometry.setType((String) objectGeometry.get("type")); Log.e("objectGeometry:", "" + objectGeometry); //problems geometry.setCoordinatesPoint((double[]) objectGeometry.get("coordinates")); 

JSON:

"features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ 2.1163, 48.8288 ] }, 

I am trying to recover the value coordinates of my json which is a double array. Thank you for your help.

2
  • As the error says, your get call returns a JSONArray. You can't cast this directly to double [] so you'll have to iterate over the array yourself and cast each item to a double. Commented Nov 15, 2019 at 10:58
  • 1
    @m pierre You must confirm and vote to the answer that was sent earlier! Commented Nov 16, 2019 at 11:14

2 Answers 2

1

coordinates is a JSONArray in your JSON , so you cannot cast it to double!

 geometry.setCoordinatesPoint(objectGeometry.getJSONArray("coordinates").getDouble(0),objectGeometry.getJSONArray("coordinates").getDouble(1)); 
Sign up to request clarification or add additional context in comments.

Comments

0

You're trying to cast jsonArray to Double. Use this geometry.setCoordinatesPoint(objectGeometry.getJSONArray("coordinates").getDouble(0),objectGeometry.getJSONArray("coordinates").getDouble(1));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.