[英]Send int and String as param in volley
Am trying to send String and int as params in volley. 我试图发送String和int作为凌空的参数。 But it show error on String if i use Map<String,Integer> params = new HashMap<String, String>();
但是如果我使用Map<String,Integer> params = new HashMap<String, String>();
它会在String上显示错误Map<String,Integer> params = new HashMap<String, String>();
and show error on int if i use Map<String,String> params = new HashMap<String, String>();
如果我使用Map<String,String> params = new HashMap<String, String>();
并在int上显示错误 So how can i send int and String as a param in post request. 因此,如何在请求后发送int和String作为参数。
StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://www.aaa.com/insert/signup" ,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("sign_up_res", response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("error" , error.toString());
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("firstname" , PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(Local_Preference.FIRSTNAME, "Not Set") );
params.put("number" , "123");
return params;
}
};
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
1000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue requestQueue = Volley.newRequestQueue(SignUp2Activity.this);
requestQueue.add(stringRequest);
In Sql table is like firstname (varchar)
and number(int)
. 在Sql表中就像firstname (varchar)
和number(int)
。 I don't want to change the int type to varchar in sql. 我不想在sql中将int类型更改为varchar。 Is there any way to send int
and String
in a single params. 有没有办法在单个参数中发送int
和String
。
you can do this create a 你可以这样做创建一个
Map params = new HashMap(); 地图参数= new HashMap();
then 然后
params.put(key,value); // for string
params.put(key,String.valueOf(value)); // for int As suggested
Please follow the code using this my problem is solved 请使用此代码来解决我的问题
String tag_json_obj = "json_obj_req";
String url = "https://api.androidhive.info/volley/person_object.json";
ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", "Androidhive");
params.put("email", "abc@androidhive.info");
params.put("password", "password123");
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.