【发布时间】:2017-06-23 22:32:44
【问题描述】:
我正在使用 volley 进行 http 请求...将多重数据传递给服务器。代码工作正常,但只有一个 json 对象传递给服务器.. 这是我要传递给服务器以存储在服务器数据库中的内容。
"usernname":"username1","email":"email1","password":"password1"
"usernname":"username2","email":"email2","password":"password2"
"usernname":"username3","email":"email3","password":"password3"
is it right to loop through the Map<String, String>??
***protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
for(int i=0;i<3;i++){
params.put("username", username+i); //post variable in the php code.."username""email","password"
params.put("email", email+i);
params.put("password", password+i);
//registerUser();
}
return params;***
**here is the full function that i am using..**
private void registerUser() {
final String email = "user1";
final String username = "user1";
final String password = "user1";
StringRequest stringRequest = new StringRequest(Request.Method.POST,Constants.URL_REGISTER,new Response.Listener<String>() {
@Override
public void onResponse(String response) { /
try {
JSONObject jsonObject = new JSONObject(response);
Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
// Handle error
public void onErrorResponse(VolleyError error) {
// progressDialog.hide();
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
for(int i=0;i<3;i++){
params.put("username", username+i); //post variable in the php code.."username""email","password"
params.put("email", email+i);
params.put("password", password+i);
//registerUser();
}
return params;
}
};
RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
}
请帮忙!!
【问题讨论】:
-
多个 JSONObjects 的用户单个数组
-
为什么不用像this这样的RestFul服务!