我对此很陌生,我正在尝试通过 volley 发送数组内的动态对象。您可以在 http://www.jsoneditoronline.org/ 上查看. 我在编码上摸索了所以任何帮助将不胜感激。 下面是我的代码 fragment ,其中对象是动态的,我将从微调器中选择并将它们发送到服务器
[
{
"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();
}
关于android - 将数组中的 Json 对象发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38845369/