mercredi 4 mars 2015

Loading data from Retrofit issue: Expected BEGIN_ARRAY but was BEGIN_OBJECT



First, the JSON I'm getting from the server:



{
"actor": [
{
"uid": "/actor-12461615214214348149",
"subtype": "some type",
"location": {
"lat": 38.931,
"lng": -77.21
},
"prop1": 100,
"prop2": 1,
"prop3": 20,
"prop4": 80
},
{
"uid": "/actor-13893903348679219933",
"subtype": "some type",
"location": {
"lat": 38.93,
"lng": -77.21
},
"prop1": 100,
"prop2": 1,
"prop3": 20,
"prop4": 80
},
{
"uid": "/actor-13809263303067864337",
"subtype": "some type",
"location": {
"lat": 38.93,
"lng": -77.21
},
"prop1": 100,
"prop2": 1,
"prop3": 20,
"prop4": 80
}
]
}


And the POJO I wanted to load from it:



public class Actor {

private String uid;
private String subtype;
private Location loc;
private int prop1;
private int prop2;
private String prop3;
private String prop4;

public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

public String getSubtype() {
return subtype;
}

public void setSubtype(String subtype) {
this.subtype = subtype;
}

public Location getLoc() {
return loc;
}

public void setLoc(Location loc) {
this.loc = loc;
}

public int getProp1() {
return prop1;
}

public void setProp1(int prop1) {
this.prop1 = prop1;
}

public int getProp2() {
return prop2;
}

public void setProp2(int prop2) {
this.prop2 = prop2;
}

public String getProp3() {
return prop3;
}

public void setPower(String prop3) {
this.prop3 = prop3;
}

public String getProp4() {
return prop4;
}

public void setProp4(String prop4) {
this.prop4 = prop4;
}


public class Location{
private double lat;
private double lng;

public double getLng() {
return lng;
}
public void setLng(double lng) {
this.lng = lng;
}

public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}

}
}


The web service invocation I've specified is looking for an Actor[] response.


After all this, I'm seeing RetroFit's IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2


I've reviewed the other RetroFit errors posted here and they most frequently appear to be cases of people trying to load arrays when the data they are getting is a single object. Alternatively the inverse is cases where people are getting an array of objects and trying to load it into a single pojo.


In my case, though, it appears to me like I've got a good match between the array I'm trying to load and the array of simple objects coming in JSON format.


I'm clearly missing something....another pair of eyes pls?




Aucun commentaire:

Enregistrer un commentaire