android – 将数组中的Json对象发送到服务器

我对此非常陌生,我试图通过volley在数组中发送动态对象.你可以在
http://www.jsoneditoronline.org/上检查这个.

我在编码上摸索着,所以任何帮助都会受到高度赞赏.

下面是我的代码片段,其中对象将是动态的,我将从微调器中选择并将它们发送到服务器

[
   {
      "longDescription":"Carrot Cheese Paratha is perfect to attract kids as it is colorful and yummy...",
      "productName":"CARROT CHEESE PARATHA",
      "name":"Delicious Kids Meal",
      "productId":"Monday",
      "catalogName":"KIDS TIFFIN MENU",
      "categoryName":"Monday",
      "subCategoryName":"Long Break",
      "kidId":47
   },
   {
      "longDescription":"Freshly cooked Desi Ghee Paratha along with Paneer butter masala",
      "productName":"Paratha plus paneer butter masala",
      "name":"Delicious Kids Meal",
      "productId":"Monday",
      "catalogName":"KIDS TIFFIN MENU",
      "categoryName":"Monday",
      "subCategoryName":"Short Break",
      "kidId":47
   },
   {
      "longDescription":"Basmati Rice along with freshly cooked Matar Paneer (cottage Cheese)",
      "productName":"Matar paneer and Basmati Rice",
      "name":"Delicious Kids Meal",
      "productId":"Wednesday",
      "catalogName":"KIDS TIFFIN MENU",
      "categoryName":"Wednesday",
      "subCategoryName":"Short Break",
      "kidId":47
   }
]

最佳答案 您可以使用JsonArrayRequest执行此操作

RequestQueue requestQueue = Volley.newRequestQueue(this);
    final String jsonString = "your json here";
    try {
        JSONArray jsonArray = new JSONArray(jsonString);
        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, url, jsonArray, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                //
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //
            }
        });
        requestQueue.add(jsonArrayRequest);
    } catch (JSONException e) {
        e.printStackTrace();
    }
点赞