简体   繁体   English

不是原始数组:类 org.json.JSONArray

[英]Not a primitive array: class org.json.JSONArray

{ "records": [ { "id": "rec43JpMrSsSmAoGG", "createdTime": "2022-12-17T15:30:47.000Z", "fields": { "Name": "green." } }, { "id": "recBfJzGGNdwRiCWR", "createdTime": "2022-12-17T15:31:16.000Z", "fields": { "Name": "yellow." } }, { "id": "recDynbN2dibdMLvO", "createdTime": "2022-12-17T15:31:16.000Z", "fields": { "Name": "purple." } }, { "id": "recNZMK3mZda33CXU", "createdTime": "2022-12-17T15:31:16.000Z", "fields": { "Name": "brown." } }, { "id": "reca6MBTrUKQXqcIl", "createdTime": "2022-12-17T15:31:16.000Z", "fields": { "Name": "pink." } }, { "id": "recdM8t7quScDwRLF", "createdTime": "2022-12-17T15:31:16.000Z", "fields": { "Name": "orange." } }, { "id": "recq5aeM3M7Gjsif9", "createdTime": "2022-12-17T15:30:47.000Z", "fields": { "Name": "blue." } }, { "id": "recxcNttZ5UoamShI", "createdTime": "2022-12-17T15:30:47.000Z", "fields": { "Name": "red." } } ] }

its my Json file but i hew to use Volley laibery but ex.它是我的 Json 文件,但我想使用 Volley laibery 但 ex。 Not a primitive array: class org.json.JSONArray help us java code is不是原始数组:类 org.json.JSONArray 帮助我们 java 代码是

RequestQueue queue = Volley.newRequestQueue(this);
        String url ="http://loclhost:1111/json";
         JsonObjectRequest jsonArryRequest =new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
             @Override
             public void onResponse(JSONObject response) {

                 try {

                    JSONArray jsonArray = new JSONArray(response.getJSONArray("records").getJSONObject(1));

                 } catch (JSONException e) {
                     e.printStackTrace();
                     Log.d("Papa","Ex - "+e.getMessage());
                 }

             }
         }, new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError error) {
                 String errorm = error.getMessage();
                 Log.d("papa", "error : "+errorm);

             }
         });

         queue.add(jsonArryRequest);

You are initializing a new jsonArray that's not the way to do it您正在初始化一个新的 jsonArray,这不是这样做的方法

Instead of this而不是这个

JSONArray jsonArray = new JSONArray(response.getJSONArray("records").getJSONObject(1));

Do this做这个

JSONArray jsonArray = response.getJSONArray("records");
JSONObject jsonObject = jsonArray.getJSONObject(1));

By doing it this way you will also get your second json object into jsonObject variable通过这种方式,您还将获得第二个 json 对象到jsonObject变量中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到类org.json.JSONArray的编解码器 - Can't find a codec for class org.json.JSONArray 找不到类型为:class org.json.JSONArray的返回值的转换器 - No converter found for return value of type: class org.json.JSONArray Jersey&JSONArray:找不到Java类org.json.JSONArray和Java类型类org.json.JSONArray和MIME媒体类型application / json - Jersey & JSONArray: Java class org.json.JSONArray, and Java type class org.json.JSONArray, and MIME media type application/json was not found 将org.json.JSONArray转换为org.json.simple.JSONArray - Convert org.json.JSONArray to org.json.simple.JSONArray 将org.json.JSONArray插入jackson ObjectNode - Insert org.json.JSONArray into jackson ObjectNode org.json.JSONArray 到 Mulesoft 中的有效负载 - org.json.JSONArray to payload in Mulesoft org.json.JSONArray无法转换为JSONObject - org.json.JSONArray cannot be converted to JSONObject 从javax.json.JsonArray转换为org.json.JSONArray - Converting from javax.json.JsonArray to org.json.JSONArray 未找到以下类型的返回值的转换器:class org.json.JSONArray 与 JAVA Z38008DD81C0F4D79185ECFE boot81D6 - No converter found for return value of type: class org.json.JSONArray with JAVA Spring boot android中的java.lang.NoSuchMethodError:org.json.JSONArray错误 - java.lang.NoSuchMethodError:org.json.JSONArray error in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM