[英]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.