Tengo un código donde obtengo un json desde una api en android la cual almaceno en un Map, ahora no sé como obtener esos datos que llegan al map para mostrarlos en pantalla.
Añado mi código para que se entienda mejor.
De antemano, muchas gracias.
private class SendBeaconParamsTask extends AsyncTask<String,Void,Collection<Map<String,String>>> {
@Override
protected Collection<Map<String,String>> doInBackground(String... params) {
String UUID = params[0];
String major = params[1];
String minor = params[2];
Log.d("HTTP UUID",UUID);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("https://cloud.easycontext.com/api/list/ibeacon?key=aNC6-qnDB-MQoi-ir3L&appid=9663261952843665&uuid="+ UUID +"&major="+major+"&minor="+minor);
try {
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
ByteArrayOutputStream content = new ByteArrayOutputStream();
int readBytes = 0;
byte[] sBuffer = new byte[512];
while ((readBytes = inputStream.read(sBuffer)) != -1) {
content.write(sBuffer,0,readBytes);
}
String dataAsString = new String(content.toByteArray());
Log.d("HTTP RESULT", dataAsString);
Gson gson = new Gson();
Type collectionType = new TypeToken<Collection<Map<String,String>>>(){}.getType();
Collection<Map<String,String>> collection = gson.fromJson(dataAsString,collectionType);
return collection;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Collection<Map<String,String>> collection) {
Log.d("HTTP",collection.toString());
//obtain data from the map and display
}
}
mi Json es el siguiente
[
{
"id":"<id>",
"image":"<image_url>",
"title":"<title>",
"description":"<description>",
"bigtext":"<bigtext>",
"note1":"<note1>",
"note2":"<note2>",
"url":"<page_url>",
"type":"<type>"
}
]