改造 - MongoDB - 预计BEGIN_ARRAY但是BEGIN_OBJECT

时间:2016-01-09 19:58:44

标签: java mongodb retrofit retrofit2

我正在尝试从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列路径为BEGIN_OBJECT $ ...

我知道我必须改变PlantDBStructure,但我真的不知道怎么做。 请帮忙。非常感谢!

0 个答案:

没有答案