gpt4 book ai didi

android - 无法使用 volley 进行 jsonarrayrequest

转载 作者:行者123 更新时间:2023-11-29 15:43:45 24 4
gpt4 key购买 nike

我正在尝试使用 volley 发出 post 请求。

请求参数是一个json数组。

以下是我的请求参数

[
"Type",
{
"User": "email",
"password": "dimmer",

}
]

我有一个方法 frameJsonArray 来构建上面的 json 并且我按如下方式发出发布请求,

 JsonArrayRequest jsonObjectRequest = new JsonArrayRequest(Request.Method.POST, Constants.requestUrl, frameJsonArray(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getApplicationContext(),response.toString(),Toast.LENGTH_SHORT).show();


}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
hideDialog();
error.printStackTrace();

}
}
);

我在上面发出请求的代码行中遇到错误。我怎样才能解决这个问题?

以下是我的错误日志

Error:(162, 46) error: constructor JsonArrayRequest in class JsonArrayRequest cannot be applied to given types;
required: String,Listener<JSONArray>,ErrorListener
found: int,String,JSONArray,<anonymous Listener<JSONObject>>,<anonymous ErrorListener>
reason: actual and formal argument lists differ in length

下面是我的frameJsonArrayMethod

public JSONArray frameJsonArray() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("login_type", "Android");
jsonObject.put("username", email);
jsonObject.put("password", password);
jsonObject.put("short_name", null);
jsonObject.put("ip","123.421.12.21");

} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put("Login");
jsonArray.put(jsonObject);

Log.d(TAG, "he;ll " + jsonArray.toString());
Toast.makeText(getApplicationContext(), jsonArray.toString(), Toast.LENGTH_SHORT).show();
return jsonArray;

最佳答案

JsonArrayRequest req = new JsonArrayRequest(url,
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();
}
});

来源:http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

关于android - 无法使用 volley 进行 jsonarrayrequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com