我正在尝试从 mongodb 接收一些数据。这是格式,我收到:
{
"_id": {
"$oid": "56906e7ee4b0166e3b6a1a4a"
},
"plant": [
{
"documentId": "8923597",
"latitude": "51.504169",
"longitude": "7.462922",
"stage": "4",
"seeds": "erdbeere",
"createAt": "08.01.2016",
"seedColor": "red"
},
{
"documentId": "5340284",
"latitude": "51.5147365",
"longitude": "7.4640148",
"stage": "1",
"seeds": "chili",
"createAt": "24.12.2015",
"seedColor": "green"
}
]
}
我正在使用改造来获得它。
MongolabDocumentConnector jsonConnection =
retrofit.create(MongolabDocumentConnector.class);
Call call =
jsonConnection.contributors("myDBData", "myCollection", "myDocumentkey", "myApiKey");
我的结构如下所示:
public class PlantDBStructure {
public final float lat;
public final float lon;
public final int stage;
public final String seeds;
public final Date created;
public final Color seedColor;
public PlantDBStructure(float lat, float lon, int stage, String seeds, Date created, Color seedColor) {
this.lat = lat;
this.lon=lon;
this.stage=stage;
this.seeds=seeds;
this.created=created;
this.seedColor=seedColor;
}
}
当我运行代码时,我得到了异常:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: 预期 BEGIN_ARRAY 但在第 1 行第 2 列路径 $...
我知道我必须更改 PlantDBStructure,但我真的不知道怎么做。请帮忙。非常感谢!