サーバーの 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();
}
配列の長さを取得しようとすると、値はゼロです。誰かが私のエラーを見つけるのを手伝ってください。前もって感謝します!