AutoBean 复杂 JSON 解析
AutoBean complex JSON parse
我有一个复杂的 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();
但我的应用程序必须实现通用解析。
提前谢谢。
您的 BrancheAutoBean
命名错误或缺少 @PropertyName
注释:result 应为 status,并且 geometryModel 应该是 result.
那么,你的 GeometryModel
的 getGeometry
应该是 List<List<Geometry>>
。不过,我不确定 AutoBean 是否支持此功能。
我有一个复杂的 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();
但我的应用程序必须实现通用解析。 提前谢谢。
您的 BrancheAutoBean
命名错误或缺少 @PropertyName
注释:result 应为 status,并且 geometryModel 应该是 result.
那么,你的 GeometryModel
的 getGeometry
应该是 List<List<Geometry>>
。不过,我不确定 AutoBean 是否支持此功能。