[英]how to send multiple json objects /data to server using volley in android
[英]How to Send multiple Json objects by using volley in android
我想在凌空中使用post方法發送此json數據,這里是多個具有不同標簽名稱的json對象
[{"name":"hi","address":"home","Language":"English"},
{"name":"hello","address":"house","Language":"English"},
{"name":"man","address":"India","Language":"Hindi"}]
下面是我的工作代碼,這里我正在發送單個json對象,任何人都可以幫助我。 提前致謝。
private void sendMessage() {
final Map<String, String> params = new HashMap<String, String>();
String tag_json_obj = "json_obj_req";
//String url = "http://192.168.0.106:59181/api/Employees";
String url = "http://android.azurewebsites.net/kfdgf/Employees";
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Senting message...");
pDialog.show();
StringRequest req = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
pDialog.hide();
pDialog.hide();
// Toast.makeText(getApplicationContext(),"hi", Toast.LENGTH_SHORT).show();
Log.d("", response);
finish();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("", "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
pDialog.hide();
// hide the progress dialog
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", name);
params.put("address", agentId);
params.put("Language", count);
return params;
}
};
}
錯誤的編程習慣。
這些JSON對象只能通過循環服務調用來一對一發送。
如果要一次性發送此JSON對象,請遵循JSON的某些標准結構。 創建對象的JSON數組,並將其傳遞給api。
標准JSON格式,可將多個對象傳遞到單個鏡頭中,
{
"data": [{
"name": "hi",
"address": "home",
"Language": "English"
}, {
"name": "hello",
"address": "house",
"Language": "English"
}, {
"name": "man",
"address": "India",
"Language": "Hindi"
}]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.