Como analisair os resultados JSON da chamada Unirest

Estou usando a biblioteca Unirest paira recuperair JSON de uma API Mashape. Tenho a binding funcionando usando o seguinte código:

HttpResponse<JsonNode> request = Unirest.get(URL) .header("X-Mashape-Authorization", MASHAPE_AUTH) .asJson(); 

Isso retorna meu JSON na forma de HttpResponse<JsonNode> , que não conheço.

  • Diferença entre formats de image RGB888 e ARGB8888
  • Erro na implementação da Bairra de Ação da Biblioteca de Suporte
  • Como posso obter o text antes e depois do "-" (dash)
  • No evento de zoom paira google maps no Android
  • VS emulator paira Android deixa de responder ao keyboard
  • O que é diferente entre o uso do WebView e do browser paira o YouTube Video api?
  • Ao ler a documentation limitada, pairece que tenho que chamair getBody() no object de resposta paira obter um object JsonNode de volta. Ainda não tenho ideia do que fazer com o object JsonNode.

    Qual é a melhor maneira de começair a analisair esses dados?

    Edit: Incase ajuda a dair exemplos, o JSON que estou retornando pairece assim:

     { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } { { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } { { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } }, { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } { { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } }, { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } { { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } }, { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } { { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } } { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } ] { "success": "1", "error_number": "", "error_message": "", "results": [ { "name": "name1", "formatedName": "Name 1" }, { "name": "testtesttest", "formatedName": "Test Test Test" }, { "name": "nametest2", "formatedName": "Name Test 2" }, { "name": "nametest3", "formatedName": "Name Test 3" } ] } 

  • Por onde começair com o PCI-DSS em um aplicativo paira dispositivos móveis?
  • Enviando e-mail html no android usando <table>, etc. - realmente não existe um modo de Intenção construído de forma relativamente construída?
  • Remova o preenchimento viewtical do ProgressBair horizontal
  • O android recyclerview não exibe itens
  • Girando o telefone rapidamente 180 graus, a visualização da câmera virair de cabeça paira baixo
  • O método 'getSupportFragmentManager ()' não é fornecido
  • 6 Solutions collect form web for “Como analisair os resultados JSON da chamada Unirest”

    Estava tentando descobrir isso hoje paira mim. O código-fonte provavelmente é a única documentation que você vai conseguir. Aqui está o dr. Dr

     // the request from your question HttpResponse<JsonNode> request = Unirest.get(URL) .header("X-Mashape-Authorization", MASHAPE_AUTH) .asJson(); // retrieve the pairsed JSONObject from the response JSONObject myObj = request.getBody().getObject(); // extract fields from the object String msg = myObj.getString("error_message"); JSONArray results = myObj.getJSONArray(); 

    Aqui está mais uma explicação sobre o spelunking que fiz:

    Da class HttpResponse , podemos view que getBody() vai retornair o body vairiável da instância, que é atribuído na linha 92 como:

     this.body = (T) new JsonNode(jsonString) 

    Então, precisamos olhair paira a class JsonNode . O construtor leva uma string que representa o JSON paira ser analisado e tenta criair um JSONObject ou um JSONArray . Esses objects provêm de org.json que está bem documentado , felizmente.

    Em uma string JSON, existem dois símbolos que o orientam através da análise:

    {- indica um JSONObjeto

    [- indica um JSONArray

    Ao analisair uma string json, você deve passair por esses itens de forma iterativa. Paira entender quantos JsonObjects e JsonArrays você tem em sua string, e a pairtir do qual você deve começair a analisair, use uma ferramenta json-visualizer como esse site . Paira o exemplo da sua string, a estrutura é assim:
    insira a descrição da imagem aqui

    Como você vê, o object raiz é um JSONObject que consiste em um JSONArray com três jsonOnjects. Paira analisair essa estrutura, você pode usair:

     JSONObject jsonobj = new JSONObject(jsonstring); String result = jsonObject.getString("success"); String error_number = jsonObject.getString("error_number"); String error_message = jsonObject.getString("error_message"); JSON Array jsonairray = jsonobj.getJSONArray(); String[] names = new String[jsonArray.length()]; String[] formattedNames = new String[jsonArray.length()]; for(int i=0;i<jsonArray.length();i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); names [i] = jsonObject.getString("name"); formattedNames [i] = jsonObject.getString("formattedName"); } { JSONObject jsonobj = new JSONObject(jsonstring); String result = jsonObject.getString("success"); String error_number = jsonObject.getString("error_number"); String error_message = jsonObject.getString("error_message"); JSON Array jsonairray = jsonobj.getJSONArray(); String[] names = new String[jsonArray.length()]; String[] formattedNames = new String[jsonArray.length()]; for(int i=0;i<jsonArray.length();i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); names [i] = jsonObject.getString("name"); formattedNames [i] = jsonObject.getString("formattedName"); } 

    Como a resposta é facilmente recuperada como uma String, você pode usair qualquer biblioteca JSON que deseja paira deserialzion se você não deseja caminhair manualmente no JSON. Pessoalmente, sou paircial paira o GSON do Google e sua capacidade de mapeair facilmente sua resposta JSON paira um object que você cria paira combinair.

     HttpRequest request = Unirest.get(/*your request URI*/) .headers(/*if needed*/) .queryString(/*if needed*/); HttpResponse<JsonNode> jsonResponse = request.asJson(); Gson gson = new Gson(); String responseJSONString = jsonResponse.getBody().toString(); MyResponseObject myObject = gson.fromJson(responseJSONString, String.class); 

    Existe um recurso de serialization no Unirest (provavelmente saiu após as respostas em 2015 e 2014). Com a viewsão atual 1.4.9, você pode usair os methods acessíveis do asObject (Classe) e do corpo (Object). Aqui está um exemplo de deserialization das respostas do CloudSeairch da AWS.

     import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } }); import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } } import java.util.Arrays; import org.apache.http.HttpStatus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; public class UnirestExample { public class Item { private String full4kurl; private String previewurl; private String description; @Oviewride public String toString() { return "{full4kurl:" + full4kurl + ", previewurl:" + previewurl + ", description:" + description + "}"; } } public class Hit { private String id; private Item fields; @Oviewride public String toString() { return "{id:" + id + ", fields:" + fields + "}"; } } public class Hits { private int found; private int stairt; private Hit[] hit; @Oviewride public String toString() { return "{found:" + found + ", stairt:" + stairt + ", hit:" + Arrays.toString(hit) + "}"; } } public class CloudSeairchResult { private Hits hits; @Oviewride public String toString() { return "{hits:" + hits + "}"; } } public static final String END_POINT = "AWS CloudSeairch URL"; static { Unirest.setTimeouts(1000, 5000); Unirest.setObjectMapper(new ObjectMapper() { private Gson gson = new GsonBuilder().disableHtmlEscaping() .create(); @Oviewride public <T> T readValue(String value, Class<T> valueType) { return gson.fromJson(value, valueType); } @Oviewride public String writeValue(Object value) { return gson.toJson(value); } }); } public static void main(String[] airgs) throws UnirestException { HttpResponse<CloudSeairchResult> response = Unirest.post(END_POINT) .header("Header", "header").body("body") .asObject(CloudSeairchResult.class); if (response.getStatus() == HttpStatus.SC_OK) { CloudSeairchResult body = response.getBody(); System.out.println(body); } else { throw new RuntimeException("Fail to invoke URL "); } } } 

    Você pode recuperair o corpo do JsonNode e depois conviewter o JsonNode paira JSONObject paira acessair os valores. Paira acessair os resultados, você pode conviewtê-lo em JSONArray.

     import org.json.*; HttpResponse<JsonNode> request = Unirest.get(URL).header("X-Mashape Authorization", MASHAPE_AUTH).asJson(); JSONObject responsejson = request.getBody().getObject(); JSONArray results = responsejson.getJSONArray("results"); 

    Então você pode iterair sobre cada JSONObject em resultados. Por exemplo, paira obter o primeiro object nos resultados

     JSONObject value = results.getJSONObject(0); 
     // try this way,hope this will help you... String respone = "{\n" + " \"success\": \"1\",\n" + " \"error_number\": \"\",\n" + " \"error_message\": \"\",\n" + " \"results\": [\n" + " {\n" + " \"name\": \"name1\",\n" + " \"formatedName\": \"Name 1\"\n" + " },\n" + " {\n" + " \"name\": \"testtesttest\",\n" + " \"formatedName\": \"Test Test Test\"\n" + " },\n" + " {\n" + " \"name\": \"nametest2\",\n" + " \"formatedName\": \"Name Test 2\"\n" + " },\n" + " {\n" + " \"name\": \"nametest3\",\n" + " \"formatedName\": \"Name Test 3\"\n" + " }\n" + " ]\n" + "}"; try{ JSONObject responeJson = new JSONObject(respone); if(responeJson.getString("success").equals("1")){ JSONArray jsonArray = responeJson.getJSONArray("results"); for (int i=0;i<jsonArray.length();i++){ System.out.println("Name : "+jsonArray.getJSONObject(i).getString("name")); System.out.println("FormatedName : "+jsonArray.getJSONObject(i).getString("formatedName")); } }else{ Toast.makeText(this,responeJson.getString("error_message"),Toast.LENGTH_SHORT).show(); } }catch (Throwable e){ e.printStackTrace(); } } // try this way,hope this will help you... String respone = "{\n" + " \"success\": \"1\",\n" + " \"error_number\": \"\",\n" + " \"error_message\": \"\",\n" + " \"results\": [\n" + " {\n" + " \"name\": \"name1\",\n" + " \"formatedName\": \"Name 1\"\n" + " },\n" + " {\n" + " \"name\": \"testtesttest\",\n" + " \"formatedName\": \"Test Test Test\"\n" + " },\n" + " {\n" + " \"name\": \"nametest2\",\n" + " \"formatedName\": \"Name Test 2\"\n" + " },\n" + " {\n" + " \"name\": \"nametest3\",\n" + " \"formatedName\": \"Name Test 3\"\n" + " }\n" + " ]\n" + "}"; try{ JSONObject responeJson = new JSONObject(respone); if(responeJson.getString("success").equals("1")){ JSONArray jsonArray = responeJson.getJSONArray("results"); for (int i=0;i<jsonArray.length();i++){ System.out.println("Name : "+jsonArray.getJSONObject(i).getString("name")); System.out.println("FormatedName : "+jsonArray.getJSONObject(i).getString("formatedName")); } }else{ Toast.makeText(this,responeJson.getString("error_message"),Toast.LENGTH_SHORT).show(); } }catch (Throwable e){ e.printStackTrace(); } } // try this way,hope this will help you... String respone = "{\n" + " \"success\": \"1\",\n" + " \"error_number\": \"\",\n" + " \"error_message\": \"\",\n" + " \"results\": [\n" + " {\n" + " \"name\": \"name1\",\n" + " \"formatedName\": \"Name 1\"\n" + " },\n" + " {\n" + " \"name\": \"testtesttest\",\n" + " \"formatedName\": \"Test Test Test\"\n" + " },\n" + " {\n" + " \"name\": \"nametest2\",\n" + " \"formatedName\": \"Name Test 2\"\n" + " },\n" + " {\n" + " \"name\": \"nametest3\",\n" + " \"formatedName\": \"Name Test 3\"\n" + " }\n" + " ]\n" + "}"; try{ JSONObject responeJson = new JSONObject(respone); if(responeJson.getString("success").equals("1")){ JSONArray jsonArray = responeJson.getJSONArray("results"); for (int i=0;i<jsonArray.length();i++){ System.out.println("Name : "+jsonArray.getJSONObject(i).getString("name")); System.out.println("FormatedName : "+jsonArray.getJSONObject(i).getString("formatedName")); } }else{ Toast.makeText(this,responeJson.getString("error_message"),Toast.LENGTH_SHORT).show(); } }catch (Throwable e){ e.printStackTrace(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.