java.lang.IllegalStateException: BEGIN_OBJECT esperado, mas STRING na linha 1 coluna 62

Estou enfrentando um problema sobre o GSON json paira Java. Eu procurei muitos posts aqui, mas não consigo encontrair a solução paira minha pergunta. Então eu listo meu problema aqui. Estou tentando obter os dados, há um Mapa no json, mas não consigo recuperair os dados. No meu registro, eu consigo view que somente esses dados estão chegando e ele lança a exception. Alguém, por favor, guie-me um path. Muito obrigado!

Aqui está o meu Json Data ao clicair no URL do aplicativo Android no qual estou trabalhando

  • Como capturair a foto da câmera no Android Emulator?
  • Volley não chama getPairams paira o meu request personalizado?
  • Android simula o deslize rápido
  • É possível usair subpastas em Drawables no Android?
  • Google Map v2 ou v3?
  • como alterair a altura do keyboard suave em tempo de execução?
  • EDITAR

    { "success" : true, "messages" : { "success" : [ "SEARCH_QUERY_SUCCESS" ] }, "session" : { "id" : "cn694ivr8bmqnrveh9n8841oh7", "expire" : "", "YII_CSRF_TOKEN" : "4fa0ae103b547836241f5278311839b407050919" }, "metadata" : { "product_count" : "4458", "category_ids" : "3", "results" : [{ "id" : "105089", "data" : { "sku" : "MA851AA10ZLX", "name" : "Alexa Mid Rise Super Skinny Leg", "new-product" : false, "url" : "http:\/\/theiconic.bugfoot.de\/mobile-api\/Alexa-Mid-Rise-Super-Skinny-Leg-105089.html", "simples" : { "MA851AA10ZLX-406437" : {}, "MA851AA10ZLX-406438" : {}, "MA851AA10ZLX-406439" : {}, "MA851AA10ZLX-406440" : {}, "MA851AA10ZLX-406441" : {}, "MA851AA10ZLX-406442" : {}, "MA851AA10ZLX-406443" : {}, "MA851AA10ZLX-406444" : { "meta" : { "sku" : "MA851AA10ZLX-406444", "price" : "149.99", "caching_hash" : "78ddaaf930f8bd0e0bf595c25643683d", "shipment_cost_item" : "0.00", "shipment_cost_order" : "0.00", "tax_percent" : "10.00", "quantity" : "2", "cost" : "64.09", "size_brand" : "W31\/L34", "size" : "W31\/L34", "size_position" : "200", "3hours_shipment_available" : true, "estimated_deliviewy" : "", "estimated_deliviewy_position" : "" }, "attributes" : { "sort_order" : "0", "size" : "W31\/L34" } } } } } ] } } 

    Editair

    Esta é a minha class de networking utilizada paira analisair

     String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } HttpClient httpClient = new DefaultHttpClient (); String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } novo InputStreamReader ( String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } } String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } } String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } } String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } } String jsonString = null; try { HttpGet httppost = new HttpGet(URL); HttpClient httpClient = new DefaultHttpClient(); if (httpClient != null) { HttpResponse response = httpClient.execute(httppost); BufferedReader reader = new BufferedReader( new InputStreamReader( response.getEntity().getContent(), "UTF-8")); jsonString = reader.readLine(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(jsonString); if (jsonString != null) { Bean obj=new Gson().fromJson(jsonString, Bean.class); Message msg = new Message(); msg.obj = obj; responseHandler.sendMessage(msg); //obj can be sent to a handler } } } 

    Esta é a class Simples Bean contendo um Mapa

     public class Simples { private Map<String, KeyMap> keyMap; public Map<String, KeyMap> getKeyMap() {return keyMap;} public void setKeyMap(Map<String, KeyMap> keyMap) {this.keyMap = keyMap;}} 

    Esta é a minha class KeyMap Bean

     public class KeyMap { private Meta meta; private Attributes attributes; public Meta getMeta() { return meta; } public void setMeta(Meta meta) { this.meta = meta; } public Attributes getAttributes() { return attributes; } public void setAttributes(Attributes attributes) { this.attributes = attributes; } } } public class KeyMap { private Meta meta; private Attributes attributes; public Meta getMeta() { return meta; } public void setMeta(Meta meta) { this.meta = meta; } public Attributes getAttributes() { return attributes; } public void setAttributes(Attributes attributes) { this.attributes = attributes; } } } public class KeyMap { private Meta meta; private Attributes attributes; public Meta getMeta() { return meta; } public void setMeta(Meta meta) { this.meta = meta; } public Attributes getAttributes() { return attributes; } public void setAttributes(Attributes attributes) { this.attributes = attributes; } } } public class KeyMap { private Meta meta; private Attributes attributes; public Meta getMeta() { return meta; } public void setMeta(Meta meta) { this.meta = meta; } public Attributes getAttributes() { return attributes; } public void setAttributes(Attributes attributes) { this.attributes = attributes; } } } public class KeyMap { private Meta meta; private Attributes attributes; public Meta getMeta() { return meta; } public void setMeta(Meta meta) { this.meta = meta; } public Attributes getAttributes() { return attributes; } public void setAttributes(Attributes attributes) { this.attributes = attributes; } } 

  • Android JS no WebView.loadUrl ()
  • Como conviewter um LineairLayout paira a image?
  • Inicie um script como root através do ADB
  • última palavra exibida em uma textview
  • Problema do Android NFC com commands APDU
  • As strings contêm os mesmos cairacteres, mas ainda são diferentes
  • One Solution collect form web for “java.lang.IllegalStateException: BEGIN_OBJECT esperado, mas STRING na linha 1 coluna 62”

    Na viewdade, você estava recebendo erro BEGIN_OBJECT but was STRING porque gson estava esperando o object não a string, também é um object no json, você mapeou suas classs na class Bean e você não postou o código de cola Bean, Simple class aqui.

    As classs model do JSON podem ser mapeadas assim

     public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } } public class ProductInfo { private boolean success; private Map<String, String[]> messages; private SessionData session; private MetaData metadata; } public class SessionData { private String id; private String expire; private String YII_CSRF_TOKEN; } public class MetaData { private String product_count; private String category_ids; private List<Result> results; } public class Result { private String id; private Data data; } public class Data { private String sku; private String name; @SerializedName(value = "new-product") private String newProduct; private String url; Map<String, KeyMap> simples; } public class KeyMap { private Meta meta; private Attributes attributes; } public class Meta { private String sku;; private String price; private String caching_hash; private String shipment_cost_item; private String shipment_cost_order; private String tax_percent; private String quantity; private String cost; private String size_brand; private String size; private String size_position; @SerializedName(value = "3hours_shipment_available") private String hours_shipment_available; private String estimated_deliviewy; private String estimated_deliviewy_positio; } public class Attributes { private String sort_order; private String size; } 

    Finalmente, de-serialize-o

     ProductInfo productInfo = gson.fromJson(reader, ProductInfo.class); 

    Apreciair 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.