繁体   English   中英

如何在Android中使用Volley发送多个Json对象

[英]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.

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