长话短说,即时尝试将一些参数发布到我的服务器中,我正在使用for循环:
public void goForOrder(int sum) {
for (int i = 0; i < forOrderArrayList.size(); i++)
{
ProductForOrder pfo = forOrderArrayList.get(i);
int branchId = pfo.getBranch(i);
int quanInBranch = pfo.getQuantity(i);
if (sum < quanInBranch){
branch = branchId;
query();
}
else {
for (int j = 0; j <pfo.getNumOfBranchs(); j++){
branch = pfo.getIdBranch(j);
query();
}
}
}
}
public void query(){
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_INDEX,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
int success = jObj.getInt("success");
if (success == 1) {
}
else {
// Toast.makeText(MainActivity.this, "Invalid ", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
}
})
{
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
params.put("status", "1");
params.put("branch", String.valueOf(branch));
return params;
}
};
requestQueue.add(stringRequest);
}
我真的不知道它是怎么回事,但是如果我一步一步地在调试模式下,我会在我的数据库中获取正确的值(例如):
branchId = 4;
branchId = 1;
branchId = 2;
但是如果在正常模式下使用它,那么字符串请求将仅将最后一个参数应用于我在此循环中发送到我的数据库中的所有先前参数:
branchId = 2;
branchId = 2;
branchId = 2;
怎么可能? 请帮帮忙?!