我想使用POST从设备到服务器JsonObjectVolley,但找不到任何代码示例。如果你能提供一些参考资料或一些代码示例。

最佳答案

我是这样做的

public void doRequest(RequestQueue volleyRequestQueue,
        onResponse responseListener) {

    this._responseListener = responseListener;

    StringRequest stringRequest = new StringRequest(Method.POST,
            Settings.QUESTIONURL, this, this) {

        public String getBodyContentType() {
            return "application/json; charset=" + getParamsEncoding();
        }

        public byte[] getBody() throws AuthFailureError {
            try {
                return new GsonBuilder()
                        .excludeFieldsWithoutExposeAnnotation().create()
                        .toJson(YOUROBJECT).toString()
                        .getBytes(getParamsEncoding());
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10000, MAXRETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    volleyRequestQueue.add(stringRequest);
}

07-27 20:57