我是新Android和我有,我不能與服務器通信和JSONs解決問題更大:接聽JSON比Android的
我從服務器接收使用JSON對象HttpClient的類,像很多的例子,我已經看到:
//Crear un cliente por defecto
HttpClient mCliente = new DefaultHttpClient();
//Indicar la url
StringBuilder sb = new StringBuilder([SERVER]);
//Establecer la conexión después de indicar la url
HttpPost mPost = new HttpPost(sb.toString());
//Creamos una lista de atributos
List<BasicNameValuePair> paresNombreValor = new ArrayList<BasicNameValuePair>();
//Añadimos los elementos a la lista
paresNombreValor.add(new BasicNameValuePair("operacion", "1")); //Operación Login
paresNombreValor.add(new BasicNameValuePair("email", stringCorreo));
paresNombreValor.add(new BasicNameValuePair("password", stringPass));
//UrlEncodedFormEntity : Codificamos la lista para el envio por post
mPost.setEntity(new UrlEncodedFormEntity(paresNombreValor));
//Ejecutamos la solicitud y obtenemos una respuesta
HttpResponse respuesta = mCliente.execute(mPost);
//Obtenemos el contenido de la respuesta
HttpEntity entity = respuesta.getEntity();
//Convertimos el stream a un String
BufferedReader buf = new BufferedReader(new InputStreamReader(entity.getContent()));
StringBuilder sb1 = new StringBuilder();
String line = null;
while ((line = buf.readLine()) != null) {
sb1.append(line + "\r\n");
}
res = sb1.toString();
if (res != null)
{
JSONArray resultadoJSON= new JSONArray(res); //<-- Here is my problem
...
的問題是,我收到JSON比字符串大,我還沒有找到其他的方式來接收轉換成JSON不以內容爲參數使用String。
任何想法?
非常感謝您
你是什麼意思大於一個字符串? –
在JSONArray中嘗試使用JSONObject而不是JSONArray resultadoJSON = new JSONArray(res); – VIGNESH
大於字符串的最大大小 – user2377195