org.json.JSONArray 无法转换为 double[]

org.json.JSONArray cannot be cast to double[]

型号:

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
                ]
            },

我正在尝试恢复我的 json 的值坐标,它是一个双精度数组。 谢谢你的帮助。

coordinatesJSONArray 中的 JSON ,因此您不能将其转换为 double!

 geometry.setCoordinatesPoint(objectGeometry.getJSONArray("coordinates").getDouble(0),objectGeometry.getJSONArray("coordinates").getDouble(1));

您正在尝试将 jsonArray 转换为 Double。使用这个 geometry.setCoordinatesPoint(objectGeometry.getJSONArray("coordinates").getDouble(0),objectGeometry.getJSONArray("coordinates").getDouble(1));