0

我有一个复杂的 JSON 字符串,我尝试使用 AutoBean 解析它。

JSON 字符串如下所示:

 `{
 "status": "OK",
 "result": {
  "geometry": [
   [
    {
     "X": 268347.4,
     "Y": 6743983.1
    },
    {
     "X": 268341.1,
     "Y": 6743989.7
    }
   ],
   [
    {
     "X": 268378.15,
     "Y": 6743972.7
    },
    {
     "X": 268347.4,
     "Y": 6743983.1
    }
   ]
  ]
 }
}`

我创建了这个界面

public interface BrancheAutoBean {

  String getResult();
  GeometryModel getGeometryModel()
}

public interface GeometryModel {
  @PropertyName("geometry")
    List<Geometry> getGeometry();
}

public interface Geometry{

  @PropertyName("X")
   Double getX();

  @PropertyName("Y")
   Double getY();
}

我怎样才能让它工作?以及如何将 X 和 Y 数组添加到几何中我发现了一些示例,例如在解析 bean 时添加 X 和 Y:

Geometry bean =AutoBeanCodex.decode(factory, GeometryModel.class, "{\"Geometry\": " + strResponse + "}").as();

但我的应用程序必须实现 générique 解析。提前谢谢。

4

1 回答 1

1

BrancheAutoBean的名称错误或缺少@PropertyName注释:result应该是status,而geometryModel应该是result

那么,你GeometryModel的 'sgetGeometry应该是List<List<Geometry>>. 不过,我不确定 AutoBean 是否支持这一点。

于 2015-07-25T09:47:42.360 回答