org.json.JSONArray无法转换为android中显示的JSONObject

org.json.JSONArray无法转换为android中显示的JSONObject,android,json,android-volley,jsonexception,Android,Json,Android Volley,Jsonexception,Iam正在创建一个android应用程序来读取json值webservice。服务在json响应后返回 [{"pk_int_kv_category_id":1,"vchr_kv_category_name":"Parent","fk_int_kv_category_id":1,"vchr_delete_status":"s","vchr_last_modified_by":1,"vchr_last_modified_time":1},{"pk_int_kv_category_id":2,"vch

Iam正在创建一个android应用程序来读取json值webservice。服务在json响应后返回

[{"pk_int_kv_category_id":1,"vchr_kv_category_name":"Parent","fk_int_kv_category_id":1,"vchr_delete_status":"s","vchr_last_modified_by":1,"vchr_last_modified_time":1},{"pk_int_kv_category_id":2,"vchr_kv_category_name":"Events","fk_int_kv_category_id":1,"vchr_delete_status":"s","vchr_last_modified_by":123,"vchr_last_modified_time":"2017-08-23 14:46:04"}]
我的程序的以下部分从url获取json值

public void makeJSONRequest(String categoryurl, String JSON_ARRAY, final String pk_int_kv_category_id_obj, final String vchr_kv_category_name_obj, final String fk_int_kv_category_id_obj, final String vchr_delete_status_obj, final String vchr_last_modified_by_obj, final String vchr_last_modified_time_obj) {
    //listAdapter.notifyDataSetChanged();
    //newsItems.clear();
    pDialog = new ProgressDialog(this);
    pDialog.setMessage("Downloading Latest News...");
    pDialog.show();
    //JSONObject jsonObject = null;

    JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET,
            categoryurl, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            VolleyLog.d(TAG, "Response: " + response.toString());
            //Toast.makeText(MainActivity.this,response.toString(),Toast.LENGTH_LONG).show();
            if (response != null) {
                Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_LONG).show();
                parseJsonFeed(response, pk_int_kv_category_id_obj, vchr_kv_category_name_obj, fk_int_kv_category_id_obj, vchr_delete_status_obj, vchr_last_modified_by_obj, vchr_last_modified_time_obj);
                hidePDialog();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),error.getMessage().toString(),Toast.LENGTH_LONG).show();
        }
    });

    //Creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    //Adding our request to the queue
    requestQueue.add(jsonReq);
}


protected void parseJsonFeed(JSONObject response, String pk_int_kv_category_id, String vchr_kv_category_name, String fk_int_kv_category_id, String vchr_delete_status, String vchr_last_modified_by, String vchr_last_modified_time) {
    try {

        JSONArray categoey_array = response.getJSONArray(JSON_ARRAY);
        for(int i=0;i<categoey_array.length();i++) {
            JSONObject feedobj=(JSONObject) categoey_array.get(i);

            pk_int_kv_category_id1 = feedobj.getString(pk_int_kv_category_id);
            vchr_kv_category_name1 = feedobj.getString(vchr_kv_category_name);
            fk_int_kv_category_id1 = feedobj.getString(fk_int_kv_category_id);
            vchr_delete_status1  = feedobj.getString(vchr_delete_status);
            vchr_last_modified_by1 = feedobj.getString(vchr_last_modified_by);
            vchr_last_modified_time1 = feedobj.getString(vchr_last_modified_time);
            Toast.makeText(this,vchr_kv_category_name.toString(),Toast.LENGTH_LONG).show();

        }
    }catch (JSONException jsonexception){
        Toast.makeText(this,jsonexception.toString(),Toast.LENGTH_LONG).show();

    }
}
public void makeJSONRequest(字符串类别URL、字符串JSON数组、最终字符串pk\u int\u kv\u category\u id\u obj、最终字符串vchr\u kv\u category\u name\u obj、最终字符串fk\u int\u kv\u category\u id\u obj、最终字符串vchr\u delete\u status\u obj、最终字符串vchr\u last\u modified\u by\u obj、最终字符串vchr\u last\u modified\u时间obj){
//listAdapter.notifyDataSetChanged();
//newitems.clear();
pDialog=新建进度对话框(此对话框);
setMessage(“下载最新新闻…”);
pDialog.show();
//JSONObject JSONObject=null;
JsonObjectRequest jsonReq=新的JsonObjectRequest(Request.Method.GET,
categoryurl,null,新响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
d(标记“Response:+Response.toString());
//Toast.makeText(MainActivity.this,response.toString(),Toast.LENGTH_LONG.show();
if(响应!=null){
Toast.makeText(getApplicationContext(),“Connected”,Toast.LENGTH_LONG.show();
parseJsonFeed(响应、pk_int_kv_category_id_obj、vchr_kv_category_name_obj、fk_int_kv_category_id_obj、vchr_delete_status_obj、vchr_last_modified_by_obj、vchr_last_modified_time_obj);
hidePDialog();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
Toast.makeText(getApplicationContext(),error.getMessage().toString(),Toast.LENGTH_LONG).show();
}
});
//创建请求队列
RequestQueue RequestQueue=Volley.newRequestQueue(this);
//将我们的请求添加到队列中
add(jsonReq);
}
受保护的void parseJsonFeed(JSONObject响应、字符串pk_int_kv_category_id、字符串vchr_kv_category_名称、字符串fk_int_kv_category_id、字符串vchr_delete_状态、字符串vchr_last_modified_by、字符串vchr_last_modified_时间){
试一试{
JSONArray categoy_array=response.getJSONArray(JSON_array);
对于(int i=0;i更改此行

JSONArray categoey_array = response.getJSONArray(JSON_ARRAY);

JSONObject feedobj=(JSONObject) categoey_array.get(i);


调用
JsonArrayRequest
而不是
JsonObjectRequest
。谢谢:-)@Krupa KakkadHappy Coding。。!
JSONArray categoey_array = new JSONArray(json string);//put here your json string

JSONObject feedobj = categoey_array.getJSONObject(i);