android - Http请求从ASHX返回空JSONArray

时间:2012-10-19 19:23:43

标签: android http

服务器中的ashx发送此响应:

[
    {
        "Dominio": "123",
        "CoTransporte": 1,
        "Descripcion": "Suzuki Fun Negro 5 Puertas",
        "Anio": "2005",
        "Titular": "Jorge Gonzalez",
        "CoDocumento": 96,
        "Documento": "31541344",
        "Domicilio": "Av. Santa Fe 2564",
        "Localidad": "Capital Federal",
        "Seguro": "Mapfre Aconcagua",
        "Poliza": "678542134",
        "Propio": false
    },
    {
        "Dominio": "UJE666",
        "CoTransporte": 1,
        "Descripcion": "Renault Fuego Marron 3 Puertasq",
        "Anio": "1986",
        "Titular": "Mauro Almendros",
        "CoDocumento": 96,
        "Documento": "31541344",
        "Domicilio": "Av. Santa Fe 2564",
        "Localidad": "Capital Federal",
        "Seguro": "Mapfre Aconcagua",
        "Poliza": "678542134",
        "Propio": false
    }
]

这是我处理响应的android代码:

// Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(this.GetVehiculosHandlerURL());
            String json  = "";

            try {
                // Add your data
                //httppost.addHeader("Content-type", "application/x-www-form-urlencoded");

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

                nameValuePairs.add(new BasicNameValuePair("dominio", dominio));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity ent = response.getEntity();
                if (ent != null)
                {
                    InputStream instream  = ent.getContent();
                    String result = convertStreamToString(instream);
                    JSONArray j = new JSONArray(result);
                    System.out.println(j.length());
                    instream.close();

                }

当我尝试获取数组长度时,值为零。请有人帮我找到我的错误。提前谢谢!

0 个答案:

没有答案