数据未在服务器上传送

时间:2014-03-13 10:37:20

标签: android json

我发送了一个Json data到服务器,但是服务器没有收到..

这是代码。

                    InputStream inputStream = null;
        String result = "";
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    try {

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httpPost = new HttpPost(url);

        String json = "";

        JSONObject jsonObject = object;

        json = jsonObject.toString();

        Log.i(TAG , "sendAddressJSON - JSON:"+json);
        // ** Alternative way to convert Person object to JSON string usin Jackson Lib 
        // ObjectMapper mapper = new ObjectMapper();
        // json = mapper.writeValueAsString(person); 
        nameValuePairs.add(new BasicNameValuePair("order",json));
        //StringEntity se = new StringEntity(json);

        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");

        HttpResponse httpResponse = httpclient.execute(httpPost);

        inputStream = httpResponse.getEntity().getContent();

        if(inputStream != null)
            result = convertInputStreamToString(inputStream);
        else
            result = "Did not work!";
        Log.i(TAG, "Response:"+result);
    } catch (Exception e) {
        Log.e("InputStream", e.getLocalizedMessage());
    }

我传递给这种方法的JSON是:

{
    "timestamp": "",
    "pincode": 998998,
    "first_name": "sangu",
    "phone": 6686656386,
    "order": [
        {
            "no_of_copies": "4",
            "product_code": "8 PASSPORT",
            "total_cost": 2400,
            "unit_cost": "600",
            "file": "egk1"
        }
    ],
    "payment": {
        "transcation_date": "13/03/2014",
        "payment_status": 100,
        "total_cost": "600",
        "transcation_id": ""
    },
    "address": "hhxjjd",
    "email": "ffggh@hhj.bbb",
    "state": "bjxhch",
    "last_name": "lastnr",
    "country": "India",
    "city": "njjcjnf"
}

0 个答案:

没有答案