【发布时间】:2019-06-16 01:18:42
【问题描述】:
我将使用 Volley 库将JsonObjectRequest 作为表单数据发送到服务器。我检查了类似的问题。他们都没有解决我的问题。
这是我需要的确切请求的 Postman 屏幕截图:
这是我的 JSONObject,名为 myKey,其中包含一个 JSONArray:
{
"myArray":[
{
"code":"FA95",
"id":"94"
}
]
}
这是我的请求方法:
public static void getSomething(String url) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public byte[] getBody() {
return super.getBody();
}
};
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
AppController.getInstance().addToRequestQueue(request);
}
我是否应该覆盖getBody()?它应该返回什么?
【问题讨论】:
-
看这个链接coderzheaven.com/2017/06/30/…希望对你有帮助
-
不幸的是,它没有!
-
你想将 json 数组作为 String 还是 Object 发送?
-
我想我应该把它作为对象发送。但是……没有区别。我只想得到服务器的真实响应。
标签: android json android-volley jsonobjectrequest