如何使用Android中的Volley库以JSON格式发送用户登录数据?

时间:2018-09-21 13:43:43

标签: java android json android-volley

我想将用户登录信息的以下JSON数据发送到服务器,以验证并接收来自服务器响应的确认。

我要发送数据的JSON格式是:

{"email":"test@gmail.com","password":"12345678","conf_password":"12345678"}

注意:我正在使用凌空库和StringRequest来发送数据和接收数据。

目前,它以这种格式发送数据

email=test%40gmail.com

1 个答案:

答案 0 :(得分:0)

如果您使用的是Request方法GET

使用

    JSONObject postData = new JSONObject();
       try {
        postData.put("name", name.getText().toString());
         ...
        // add more data and put to postdata

    } catch (JSONException e) {
        e.printStackTrace();
    }

并将postData发送到url,例如www.abc.com?stingjson=postData

如果您使用的是Requst方法发布

使用

之前; 添加此代码

{
    @Override
    protected Map<String,String> getParams(){
      JSONObject postData = new JSONObject();
       try {
        postData.put("name", name.getText().toString());
         ...
        // add more data and put to postdata

    } catch (JSONException e) {
        e.printStackTrace();
    }
        Map<String,String> params = new HashMap<String, String>();
        params.put("YourProperty",postData );


        return params;
    }