我想将用户登录信息的以下JSON数据发送到服务器,以验证并接收来自服务器响应的确认。
我要发送数据的JSON格式是:
{"email":"test@gmail.com","password":"12345678","conf_password":"12345678"}
注意:我正在使用凌空库和StringRequest来发送数据和接收数据。
目前,它以这种格式发送数据
email=test%40gmail.com
等
答案 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;
}