2014-07-12 8 views
6

Sto utilizzando Retro Fit per connettersi all'API online. Ma sto ricevendo questo errore mentre cercavo di analizzare i dati restituiti.java.lang.IllegalStateException: previsto BEGIN_ARRAY ma era BEGIN_OBJECT alla riga 1 colonna 2

retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 

I dati che vengono restituiti in formato This e il modello per i dati è dato anche al di sotto:

iGPlaceApi.getStreams(ITEMS_PER_PAGE, pageNumber * ITEMS_PER_PAGE, new Callback<List<mGooglePlacesApiResponse>>() { 

      @Override 
      public void success(List<mGooglePlacesApiResponse> mGp, Response response) { 
       int n = mGp.size(); 
       Object asa = mGp.toArray(); 
      } 

      @Override 
      public void failure(RetrofitError retrofitError) { 
       String error = retrofitError.toString(); 
      } 
     }); 

public class mGooglePlacesApiResponse { 

    public String html_attributions; 
    //public List<String> html_attributions; 
    public String next_page_token; 
    public List<place> results; 
} 

public class place { 

    public Geometry geometry; 
    public String icon; 
    public String id; 
    public String name; 
    public OpeningHours opening_hours; 
    public List<Photo> photo 
    ... 
+2

tua JSON inizia con jsonarray? – Raghunandan

risposta

8

Change List<mGooglePlacesApiResponse> mGp-mGooglePlacesApiResponse mGp. Il tuo JSON contiene oggetti non elencati.

@EDIT

Btw, html_attributions è un array

@ edit2

Bene, vedo che i tuoi corretti html_attrubutions

+0

salvato il giorno. Grazie! – Maven

+0

Il mio errore era il contrario – Cabezas

Problemi correlati