Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 提取JSON类型不匹配错误消息_Java_Android_Json - Fatal编程技术网

Java 提取JSON类型不匹配错误消息

Java 提取JSON类型不匹配错误消息,java,android,json,Java,Android,Json,我在尝试从JSON提取数据时遇到了一些问题。基本上,这是我的JSON格式: 以下是代码: public void getDirection(Event eventModel){ String eventX = eventModel.getEventX(); Log.i("X", eventX); String eventY = eventModel.getEventY(); Log.i("Y", eventY); SimpleLineSymbol l

我在尝试从JSON提取数据时遇到了一些问题。基本上,这是我的JSON格式:

以下是代码:

public void getDirection(Event eventModel){
    String eventX = eventModel.getEventX();
    Log.i("X", eventX);

    String eventY = eventModel.getEventY();
    Log.i("Y", eventY);

    SimpleLineSymbol lineSymbol = new SimpleLineSymbol(
            Color.GREEN, 3, SimpleLineSymbol.STYLE.DASH);
    List pointArr = null;
    String page;
    JSONArray jsonArray;

    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet("http://www.onemap.sg/API/services.svc/route/solve?token=qo/s2TnSUmfLz+32CvLC4RMVkzEFYjxqyti1KhByvEacEdMWBpCuSSQ+IFRT84QjGPBCuz/cBom8PfSm3GjEsGc8PkdEEOEr&routeStops=18304.68,36152.73;" + eventX + "," + eventY + "&routemode=DRIVE&avoidERP=0&routeOption=shortes");
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");
        page = responseString ;
        try {
            JSONObject jsonObject = new JSONObject(page);
            jsonArray = jsonObject.getJSONArray("routes");
            Log.i("Array", jsonArray.toString());
            JSONObject features = jsonArray.getJSONObject(3);
            //String geometry = features.getString("geometry");
            JSONArray paths = features.getJSONArray("paths");
            int length = paths.length();
            for (int i = 0; i < length; i++) {
                JSONObject attribute = paths.getJSONObject(i);
                    String path = attribute.getString("paths");
                    pointArr.add(path);
                    /*path = path.replace("[[\"", "");
                    path = path.replace("\"]]", "");
                    String[] arr = path.split(";");
                    for (int j = 0; j < arr.length; j++) {
                        String[] point = arr[j].split(",");
                        pointArr.add(point);
                    }*/

            }
            Graphic lineGraphic = new Graphic((Geometry) pointArr, lineSymbol);
            graphicsLayer.addGraphic(lineGraphic);  
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
有导游吗?提前谢谢

编辑

JSONObject jsonObject = new JSONObject(page);
            /*JSONObject myObject = jsonObject.getJSONObject("routes");
            JSONArray features = jsonArray.getJSONArray(3);*/
            JSONObject geometry = jsonObject.getJSONObject("geometry");
            jsonArray = geometry.getJSONArray("paths");
            int length = geometry.length();
            for (int i = 0; i < length; i++) {

                JSONObject attribute = jsonArray.getJSONObject(i);
                    String path = attribute.getString("paths");
                    path = path.replace("[[\"", "");
                    path = path.replace("\"]]", "");
                    String[] arr = path.split(";");
                    for (int j = 0; j < arr.length; j++) {
                        String[] point = arr[j].split(",");
                        pointArr.add(point);
                    }

            }
JSONObject JSONObject=新的JSONObject(第页);
/*JSONObject myObject=JSONObject.getJSONObject(“路由”);
JSONArray features=JSONArray.getJSONArray(3)*/
JSONObject geometry=JSONObject.getJSONObject(“geometry”);
jsonArray=geometry.getJSONArray(“路径”);
int length=geometry.length();
for(int i=0;i
“路由”是一个对象而不是数组

JSONObject myObject = jsonObject.getJSONObject("routes");

我有一种预感,您在json上调用了错误的数据类型。这意味着当对象是字符串或数组等时,您正在请求对象。第100行是什么?@Jawascript问题甚至不在第100行。。。问题出现在EventController的第222行。这是因为您正试图从一个似乎是objectLine的对象创建一个数组,这一行是:jsonArray=jsonObject.getJSONArray(“routes”);我试图使用日志打印出来,但它甚至没有显示上线222是这一行:jsonArray=jsonObject.getJSONArray(“routes”);我试图用日志打印出来,但它甚至没有显示出来,请解释:)但是如果我将其更改为JSONObject,那么我应该如何修改下面与它相交的部分?只需替换
jsonArray
for
myObject
的内容,你能帮我检查一下我的几何体是JSONObject还是数组吗?如果我这样做:jsonobjectfeatures=JSONObject.getJSONObject(“features”);,我收到“无特征值错误消息”
几何体是一个对象<代码>路径
是一个数组。你有什么想法吗?
JSONObject myObject = jsonObject.getJSONObject("routes");