如何使用volley解析android中的json数据

时间:2022-10-22 20:27:59

I have following JSON data. I m unable to get specific record from this data i.e id , createdd_at , total or order_no etc in android with volley.

我有以下JSON数据。我无法从这些数据中获取特定记录,例如id,created,createdd_at,total或order_no等在android中使用volley。

stdClass Object (
 [order] => stdClass Object 
       (
        [id] => 15461 
        [order_number] => 15461
        [created_at] => 2016-09-27T17:59:17Z 
        [total] => 1495.00
               ( 
                [0] => stdClass Object ( 
                     [id] => 26
                     [first_name] => Saleem 
                     [last_name] => Rafiq 
       )          )          )         )

and here is my volley code

这是我的截击码

StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                    new Response.Listener<String>() {
     @Override
       public void onResponse(String response) {
       try {
           JSONObject jsonObject = new JSONObject(response);
           JSONArray jsonArray = jsonObject.getJSONArray("order");
       } catch (JSONException e) {
          e.printStackTrace();
                  }
              }
         }, new Response.ErrorListener() {
      @Override
         public void onErrorResponse(VolleyError error) {
         Toast.makeText(OrderList.this,""Error, Toast.LENGTH_SHORT).show();
         }
       }) `
        };
      MySingleton.getInstance(ctx).addToRequestque(stringRequest);
        }
      });

Kindly fix my code.. I'll be thankful to you cordially.

请修理我的代码..我会亲切地感谢你。

1 个解决方案

#1


0  

Order is not a JSONArray it is JSONObject in your sample. This is what you do wrong.

Order不是JSONArray,它是您样本中的JSONObject。这就是你做错了。

#1


0  

Order is not a JSONArray it is JSONObject in your sample. This is what you do wrong.

Order不是JSONArray,它是您样本中的JSONObject。这就是你做错了。