M0286_Libro Curso

Android

is.close(); respuesta = sb.toString(); Log. e (“log_tag”, “Cadena JSon “ + respuesta); Log. e (“log_tag”, “Error converting result “

} catch (Exception e) {

+ e.toString());

throw new Exception(

“Error al recuperar las imágenes

del servidor. “);

} finally {

if (reader != null) { reader.close();

} ;

}

} Recuperamos los datos del servidor con el método JSONArray getServerData() : public JSONArray getServerData(ArrayList parametros, String URL) throws Exception { JSONArray jsonArray = null; try { conectaPost(parametros, URL); getRespuestaPost(); jsonArray = getJsonArray(); return jsonArray; } catch (Exception e) { throw new Exception(e.getMessage()); } } }

JSON Es la abreviatura de JavaScript Object Notation , y es un formato ligero que se utiliza para el intercambio de datos. JSON no requiere el uso de XML.

Y por último, ese string devuelto lo debemos convertir en un JSON Array con el que poder trabajar:

276

Made with FlippingBook - Online catalogs