JSON输出在通过数据时不正确

时间:2014-03-29 11:50:21

标签: android http-post

我使用HTTP-POST方法将数据发送到带有数据和图像的服务器。我验证了所有代码。我没有得到错误。我的问题是当我发送数据时,我得到了json

03-31 10:38:48.484: I/HTTP(28448): HTTP: OK
03-31 10:38:48.484: I/HTTP(28448): org.apache.http.conn.BasicManagedEntity@41ab71e0
03-31 10:38:48.485: I/Http Response:(28448): org.apache.http.message.BasicHttpResponse@41ab8cc8
03-31 10:38:48.489: I/MY RESPONSE(28448): {
03-31 10:38:48.489: I/MY RESPONSE(28448):   "status":0,
03-31 10:38:48.489: I/MY RESPONSE(28448):   "message":"please enter amount"
03-31 10:38:48.489: I/MY RESPONSE(28448): }

我输了数据但是输出就像“请输入金额”

请帮我解决问题。

public void postData() {

        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bao);
        byte[] ba = bao.toByteArray();
        String ba1 = Base64.encodeToString(ba, Base64.DEFAULT);

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "MY URL");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
            //nameValuePairs.add(new BasicNameValuePair("amount", et_ans
                    //.getText().toString()));
                    nameValuePairs.add(new BasicNameValuePair("amount","12.12"));
            nameValuePairs.add(new BasicNameValuePair("shop",
                    autoCompleteTextView1.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("date", txt_date
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("address", edt_address
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("state", txt_province
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("city", txt_city
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("image", ba1));

            Log.i("AMOUNT IS=", nameValuePairs.get(0).toString());
            Log.i("SHOP IS=", nameValuePairs.get(1).toString());
            Log.i("DATE IS=", nameValuePairs.get(2).toString());
            Log.i("ADDRESS IS=", nameValuePairs.get(3).toString());
            Log.i("STATE IS=", nameValuePairs.get(4).toString());
            Log.i("CITY IS=", nameValuePairs.get(5).toString());
            Log.i("IMAGE IS=", nameValuePairs.get(6).toString());

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                    HTTP.UTF_8));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            Log.i("HTTP", "HTTP: OK");
            Log.i("HTTP", response.getEntity().toString());

             Log.i("Http Response:", response.toString());



            try{
        bufferedReader = new BufferedReader(
                   new InputStreamReader(response.getEntity().getContent()));

        StringBuffer stringBuffer = new StringBuffer("");
        String line = "";
        String LineSeparator = System.getProperty("line.separator");
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line + LineSeparator); 
           }
           bufferedReader.close();

          // result.setText(stringBuffer.toString());

           Log.i("MY RESPONSE",stringBuffer.toString());
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally{
               if (bufferedReader != null){
                try {
                 bufferedReader.close();
                } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                }
               }
              }

0 个答案:

没有答案