0

我正在使用 volley 解析 json,但它不起作用并出现错误。以下是我的代码和 json 响应。请帮我解决这个问题

 private void getStaffList() {

        showpDialog();
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        final String url = "url";


        try {

            final JSONObject jsonObj = new JSONObject();


            jsonObj.put("username", "test");
            jsonObj.put("password", "123456");


            JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                    url, jsonObj, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d("TAG", "Main response=" + response);


                    staffarraylist=new ArrayList<DataModel>();;
                    try {
                        JSONObject jobSuccess=response.getJSONObject("TABLE_DATA");
                        Log.d("TAG", "JSONObj response=" + jobSuccess);
                        JSONArray jarMyData=jobSuccess.getJSONArray("data");
                        Log.d("TAG", "JSONArray response=" + jarMyData);
                        for (int i = 0; i < jarMyData.length(); i++) {
                            JSONArray jar = jarMyData.getJSONArray(i);

                            DataModel movie = new DataModel();
                            movie.setName(jar.getString(0));
                            movie.setOccupation(jar.getString(1));
                            movie.setPlace(jar.getString(2));
                            movie.setId(jar.getString(3));
                            movie.setDate(jar.getString(4));
                            movie.setPrice(jar.getString(5));
                            staffarraylist.add(movie);
                        }
                    }catch (JSONException e)
                    {
                        Log.d("JSONException",e.toString());
                    }


                    rcAdapter = new RecyclerViewAdapterHome(MainActivity.this,  staffarraylist);
                    recyclerView.setAdapter(rcAdapter);

                    hidepDialog();

                }

            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("TAG", "JSONObj Error: " + error.getMessage());
                    hidepDialog();
                    //Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
                    // hide the progress dialog
                }
            });

            requestQueue.add(jsonObjReq);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

日志猫

主要回复={"TABLE_DATA":"{\"data\":[[\"Tiger Nixon\",\"System Architect\",\"Edinburgh\",\"5421\",\"2011/04/ 25\",\"$320,800\"],[\"Garrett Winters\",\"会计\",....等等

D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],[ "加勒特温特斯","会计","东京","8422","2011/07/25","$

4

1 回答 1

0

首先通过单击此处检查您的 json 格式是否正确 并粘贴您的 json 进行检查。如果响应正确,则使用 Gson。它将解析响应而没有任何错误。

于 2018-11-24T15:05:14.433 回答