【问题标题】:value org.json.jsonobject cannot be converted to jsonarray值 org.json.jsonobject 无法转换为 jsonarray
【发布时间】:2016-05-12 21:40:27
【问题描述】:

我尝试从我的数据库中添加标记,但我有一个错误值 org.json.jsonobject cannot be convert to jsonarray

05-12 22:30:18.300 2926-2926/com.example.getgpslocation W/System.err: org.json.JSONException: Value {"markers":[{"lat":"-0.6092131","lng":"35.2236078"},{"lat":"-0.6340827","lng":"35.1907590"},{"lat":"-0.6292730","lng":"35.1914282"},{"lat":"-0.6292730","lng":"35.2102234"},{"lat":"-0.6139107 ","lng":"35.2128532"},{"lat":"-0.6239696","lng":"35.2201147"},{"lat":"-0.6230255","lng":"35.2174852"},{"lat":"-0.6296344","lng":"35.2231999"},{"lat":"-0.6305786","lng":"35.2246723"},{"lat":"-0.6423803","lng":"35.2206756"},{"lat":"-0.6330677","lng":"35.2163282"},{"lat":"-0.6243836","lng":"35.2161752"},{"lat":"-0.6272590","lng":"35.2102847"},{"lat":"-0.6254565","lng":"35.2031314"},{"lat":"-0.6191050","lng":"35.2011677"},{"lat":"-0.6125390","lng":"35.1946448"},{"lat":"-0.6149852","lng":"35.1927510"},{"lat":"-0.6187617","lng":"35.1926107"},{"lat":"-0.6330677","lng":"35.2163282"},{"lat":"-0.6243836","lng":"35.2161752"},{"lat":"-0.6272590","lng":"35.2102847"},{"lat":"-0.6254565","lng":"35.2031314"},{"lat":"-0.6191050","lng":"35.2011677"},{"lat":"-0.6125390","lng":"35.1946448"},{"lat":"-0.6149852","lng":"35.1927510"},{"lat":"-0.6187617","lng":"35.1926107"},{"lat":"-0.6422793","lng":"35.1904012"},{"lat":"-0.6495749","lng":"35.1859469"},{"lat":"-0.6600892","lng":"35.1788616"},{"lat":"-0.6449401","lng":"35.1798438"},{"lat":"-0.6352412","lng":"35.1802647"},{"lat":"-0.6267440","lng":"35.1816327"},{"lat":"-0.6394620","lng":"35.2172748 "}]} of type org.json.JSONObject cannot be converted to JSONArray

这是我的代码:

 StringRequest stringRequest = new StringRequest(Request.Method.POST, AppConfig.URL_Marker,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONArray jsonArray = new JSONArray(response);


                            for (int i = 0; i < jsonArray.length(); i++) {
                                jresponse = jsonArray.getJSONObject(i);
                                latitude = Double.parseDouble(jresponse.getString("lat"));
                                longitude = Double.parseDouble(jresponse.getString("lng"));


                                mMap.addMarker(new MarkerOptions()
                                        .position(new LatLng(latitude,longitude))
                                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.tram_48))
                                        .draggable(true));

                            }


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        //pDialog.dismiss();

                    }

                }

【问题讨论】:

    标签: android mysql json google-maps


    【解决方案1】:

    你可能想试试这个:

    try{
         JSONObject jsonObj = new JSONObject(response);
         JSONArray jsonArray = jsonObj.getJSONArray("markers");
    

    因为据我所知,这应该可行。

    【讨论】:

    • JSON 问题解决了,但是标记没有显示在地图上!
    • 这是一个完全不同的问题。尝试自行调试以查看它们未显示的原因,如果它解决了您的问题,请考虑接受答案。如果您无法弄清楚为什么它们不会显示,请在 SO 上发布一个新问题。干杯兄弟! :)
    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 2013-08-24
    • 2016-06-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2015-08-11
    相关资源
    最近更新 更多