[英]How to make a Json Array Request with Request Parameters
I have to make json array request with the following request paramatetrs. 我必须使用以下请求参数进行json数组请求。
[
"Login",
{
"password": "",
"username": "",
"ip": "12.123.124.12",
"login_type": "Android"
}
]
I use volley to make post request. 我用凌空抽空提出要求。 In volley, if we have to make jsonarrayrequest, we do something like the following,
在齐射中,如果我们必须进行jsonarrayrequest,我们可以执行以下操作,
JsonArrayRequest req = new JsonArrayRequest(Constants.requestUrl,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
});
The problem is that, How can I ever be able to insert my request parameters in the above code snippet. 问题是,如何能够在上述代码段中插入我的请求参数。 In case of JsonObjectRequest, we have provision to insert as follows,
对于JsonObjectRequest,我们有如下规定要插入:
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Constants.requestUrl, frameLoginJson(),
new Response.
Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
hideDialog();
error.printStackTrace();
}
}
);
In frameLoginJson, im framing the request parameter and dispatching the request. 在frameLoginJson中,将请求参数成帧并分派请求。
But Im unable to do the same in case of JSONArrayRequest. 但是我无法在JSONArrayRequest的情况下做同样的事情。 How can I be able to make json array request with request parameters using volley especially or by any other mean?
我怎么能特别使用volley或以任何其他方式发出带有请求参数的json数组请求?
You would need to override the getParams method with the following signature: protected Map<String,String> getParams()
. 您将需要使用以下签名覆盖getParams方法 :
protected Map<String,String> getParams()
。
Here's an example: see the answer to Volley not calling getParams() for standard POST request 这是一个示例:查看Volley不为标准POST请求调用getParams()的答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.