我期待JSONArray
在最初在请求正文中传递的响应中包含JSONObjects列表。但是,我得到一个空JSONArray
的成功回复。我确信自从我在Postman上测试它以后API工作正常。
JsonArrayRequest arrayRequest = new JsonArrayRequest(DownloadManager.Request.Method.POST, URL, jsonArray,
ResSuccessListenerForJsonArray(requestType),
ResErrorListenerForJsonArray(requestType)
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers != null ? headers : super.getHeaders();
}
};
我从作业服务中产生AsyncTask
来发出请求。
以下是回复的片段:
[
{
"id": "902b7fc3-5059-4265-85eb-d00db3594af5",
"user": "test@gmail.com",
"package":"com.whatsapp",
.
.
.
},
{
"id": "902b7fc3-5059-4265-85eb-d00db3594af5",
"user": "test@gmail.com",
"package":"com.whatsapp",
.
.
.
},
.
.
.
]
这是我的回复处理程序:
private static Response.Listener<JSONArray> ResSuccessListenerForJsonArray(final String requestType) {
return new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.e("Success", "Notification data logged successfully");
if (response != null && response.length() > 0) {
try {
handleSuccess(requestType, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}