凌空org.json.JSONException [英] org.json.JSONException in volley

查看:130
本文介绍了凌空org.json.JSONException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Volley解析json,但无法正常工作并出现错误.以下是我的代码和json响应.请帮我解决这个问题

I am parsing json using volley but its not working and getting error. Follwing is my code and json reponse. please help me to solve this

 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();
        }

    }

Logcat

主要响应= {"TABLE_DATA":"{\" data \:[[\" Tiger Nixon \,\" System Architect \,\" Edinburgh \,\" 5421 \,\" 2011 /04/25 \,\" $ 320,800 \],[\" Garrett Winters \,\" Accountant \,.... so on

Main response={"TABLE_DATA":"{\"data\":[[\"Tiger Nixon\",\"System Architect\",\"Edinburgh\",\"5421\",\"2011/04/25\",\"$320,800\"],[\"Garrett Winters\",\"Accountant\",....so on

D/JSONException:org.json.JSONException:值{"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$ 320,800" ],["Garrett Winters",会计",东京","8422","2011/07/25","$

D/JSONException: org.json.JSONException: Value {"data":[["Tiger Nixon","System Architect","Edinburgh","5421","2011/04/25","$320,800"],["Garrett Winters","Accountant","Tokyo","8422","2011/07/25","$

推荐答案

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

First check that your json format is correct or not by clicking here and paste your json for checking. If the response is correct then use Gson. It will parse the response without any error.

这篇关于凌空org.json.JSONException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆