我们可以使用Android排序将JsonObject或JsonArray发布到服务器吗?如果有,请发送工作样本。 如果我发布字符串然后它工作正常但我在发布jsonObject或jsonArray时遇到了一些问题。
答案 0 :(得分:0)
是的,你可以。 JSON被添加到POST请求的主体中,如下所示:
JSONObject jsonObject; // your JSON here
requestQueue.add(new JsonObjectRequest(Method.POST, url, jsonObject, listener, errorListener);
答案 1 :(得分:0)
是的,只需将数据添加到JSONObject并在请求中传递该对象。
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("password", password);
RequestQueue queue = Volley.newRequestQueue(context);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST, URL, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("volley", "response: " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("volley", "error: " + error);
}
});