如何在android中看到json数据发送到服务器

时间:2017-02-17 07:51:10

标签: android json android-volley

我已成功将json数据发送到服务器。但发送图像时出现问题。 我尝试以下方法: -

 public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}


private void uploadImage(){
    //Showing the progress dialog
    final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://toootapp.dreamsapps.com/ToootWebservice.asmx/SaveImage",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    Log.e("img Response",s.toString().trim());
                    //Disimissing the progress dialog
                    loading.dismiss();

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    Log.e("onErrorResponse=",getIntent().getStringExtra("path"));
                    //Dismissing the progress dialog
                    loading.dismiss();

                    //Showing toast
                   // Toast.makeText(SaveImageOnServerActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            //Converting Bitmap to String

          //  Log.e("Path=",getIntent().getStringExtra("path"));
            Bitmap myBitmap = BitmapFactory.decodeFile(new File(getIntent().getStringExtra("path")).getAbsolutePath());
            String image = getStringImage(myBitmap);

            //Getting Image Name
            String name = "Computer";//editTextName.getText().toString().trim();

            //Creating parameters
            Map<String,String> params = new Hashtable<String, String>();

            //Adding parameters
            params.put("base64Image", image);


            params.put("Tags", "Computer");


            //returning parameters
            return params;
        }
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
    };

    //Creating a Request Queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);

所以我只想检查哪个json字符串要服务器。

有什么方法可以看到以下形式的json字符串

 {
    "base64Image": "",
    "Email": "abc@gmail.com",
    "MobileNo": "1234567890",
    "Website": "www.gameneeti.com",
    "Industry": "Computer"
}

我发送。 我想在日志中打印这个字符串。

感谢。

0 个答案:

没有答案