如何使用Volley在android中显示网络响应正文

时间:2019-05-24 09:26:45

标签: php android json android-volley multipart

如何使用排球在android中显示网络响应

在邮递员中得到这样的答复

enter image description here

如何在android中显示此响应?

我使用JSONobject进行了这种尝试,但没有任何反应

    VolleyMultipartRequest volleyMultipartRequest = new VolleyMultipartRequest(Request.Method.POST, URL,
            new Response.Listener<NetworkResponse>() {
                @Override
                public void onResponse(NetworkResponse response) {
                    Log.e("server", "status code: " + response.statusCode);
                    String resultResponse = new String(response.data);
                    try {

                        JSONObject result = new JSONObject(resultResponse);
                        String name = result.getString("name");
                        Log.e("sever", name + " " );
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    progressDialog.dismiss();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.e("server", "error listener: " + error.getMessage());
                    progressDialog.dismiss();
                }
            }) {


        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("name", "IMG_" + System.currentTimeMillis());
            return params;
        }

        @Override
        protected Map<String, DataPart> getByteData() {
            Map<String, DataPart> params = new HashMap<>();
            params.put("file", new DataPart("img_file", AppHelper.getFileDataFromDrawable(getBaseContext(), bitmap), "image/jpeg"));
            return params;
        }
    };

我得到NetworkResponse的响应对象,请帮助我显示响应正文

0 个答案:

没有答案