Java android中如何解析字符串的JSON数组

Java android中如何解析字符串的JSON数组,java,android,Java,Android,这是来自服务器的响应 {"route":[1,2,3,4,5,6]} 这是我的代码: try{ String d = json.getString("route"); } }catch(JSONException je){ } 我得到了NullPointerException。 请帮帮我 这是我的服务器响应,现在给我解决方案 链接->http://ajax.tpksym.cloudbees.net/route/route14它应该是这样的: JSONObject jsonResult = n

这是来自服务器的响应

{"route":[1,2,3,4,5,6]}
这是我的代码:

try{
String d = json.getString("route");
}
}catch(JSONException je){
}
我得到了NullPointerException。 请帮帮我

这是我的服务器响应,现在给我解决方案 链接->
http://ajax.tpksym.cloudbees.net/route/route14

它应该是这样的:

JSONObject jsonResult = new JSONObject("{\"route\":[1,2,3,4,5,6]}");
JSONArray array = jsonResult.getJSONArray("route");
for (int i = 0; i < array.length(); i++) {
     int data = array.getInt(i);
}
....
JSONObject jsonResult=newjsonobject(“{\'route\”:[1,2,3,4,5,6]}”);
JSONArray数组=jsonResult.getJSONArray(“路由”);
对于(int i=0;i
它应该是这样的:

JSONObject jsonResult = new JSONObject("{\"route\":[1,2,3,4,5,6]}");
JSONArray array = jsonResult.getJSONArray("route");
for (int i = 0; i < array.length(); i++) {
     int data = array.getInt(i);
}
....
JSONObject jsonResult=newjsonobject(“{\'route\”:[1,2,3,4,5,6]}”);
JSONArray数组=jsonResult.getJSONArray(“路由”);
对于(int i=0;i
它应该是这样的:

JSONObject jsonResult = new JSONObject("{\"route\":[1,2,3,4,5,6]}");
JSONArray array = jsonResult.getJSONArray("route");
for (int i = 0; i < array.length(); i++) {
     int data = array.getInt(i);
}
....
JSONObject jsonResult=newjsonobject(“{\'route\”:[1,2,3,4,5,6]}”);
JSONArray数组=jsonResult.getJSONArray(“路由”);
对于(int i=0;i
它应该是这样的:

JSONObject jsonResult = new JSONObject("{\"route\":[1,2,3,4,5,6]}");
JSONArray array = jsonResult.getJSONArray("route");
for (int i = 0; i < array.length(); i++) {
     int data = array.getInt(i);
}
....
JSONObject jsonResult=newjsonobject(“{\'route\”:[1,2,3,4,5,6]}”);
JSONArray数组=jsonResult.getJSONArray(“路由”);
对于(int i=0;i
您好,您的json如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
因此,应采取以下措施

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
当你给链接的时候

数据似乎是双倍的,比如13.56等等

所以使用如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“来自服务器的JSON数据”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
您好,您的json如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
因此,应采取以下措施

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
当你给链接的时候

数据似乎是双倍的,比如13.56等等

所以使用如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“来自服务器的JSON数据”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
您好,您的json如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
因此,应采取以下措施

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
当你给链接的时候

数据似乎是双倍的,比如13.56等等

所以使用如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“来自服务器的JSON数据”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
您好,您的json如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
因此,应采取以下措施

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
当你给链接的时候

数据似乎是双倍的,比如13.56等等

所以使用如下

{
  "route": [
    1,
    2,
    3,
    4,
    5,
    6
  ]
}
String jsondata = "{\"route\":[1,2,3,4,5,6]}";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Integer data = jarray.getInt(i);
            System.out.println("data=="+data);
        }
String jsondata = "JSON DATA FROM SERVER";
        JSONObject primaryObject = new JSONObject(jsondata);

        JSONArray jarray = primaryObject.getJSONArray("route");

        for (int i = 0; i < jarray.length(); i++) {

            Double data = jarray.getDouble(i);

        }
String jsondata=“来自服务器的JSON数据”;
JSONObject primaryObject=新的JSONObject(jsondata);
JSONArray jarray=primaryObject.getJSONArray(“路由”);
for(int i=0;i
试试看{
字符串jsonString=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject JSONObject=新的JSONObject(jsonString);
JSONArray JSONArray=jsonObject.getJSONArray(“路由”);
for(int i=0;i
试试看{
字符串jsonString=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject JSONObject=新的JSONObject(jsonString);
JSONArray JSONArray=jsonObject.getJSONArray(“路由”);
for(int i=0;i
试试看{
字符串jsonString=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject JSONObject=新的JSONObject(jsonString);
JSONArray JSONArray=jsonObject.getJSONArray(“路由”);
for(int i=0;i
试试看{
字符串jsonString=“{\'route\”:[1,2,3,4,5,6]}”;
JSONObject JSONObject=新的JSONObject(jsonString);
JSONArray JSONArray=jsonObject.getJSONArray(“路由”);
for(int i=0;i