简体   繁体   English

如何使用Volley在Android中解析JSON数据

[英]How to parse json data in android with volley

I have following JSON data. 我有以下JSON数据。 I m unable to get specific record from this data ie id , createdd_at , total or order_no etc in android with volley. 我无法从此数据获取特定记录,即id,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. 请修正我的代码。.我诚挚地感谢您。

Order is not a JSONArray it is JSONObject in your sample. 订单不是JSONArray,而是示例中的JSONObject。 This is what you do wrong. 这就是你做错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM