【发布时间】:2012-06-24 10:45:56
【问题描述】:
我喜欢使用GSON 来反序列化下面的 JSON 字符串。
{
"type": "FeatureCollection",
"features": [
{
"id": "FSROGD.4440181",
"geometry": {
"type": "Point",
"coordinates": [
16.7594706041998,
43.148716514354945
]
}
}
]
}
我已经准备好名为 Response、Features、Geometry 和 Coordinates 的必要 Java 类。除了最后一节课,一切都很好。但是对于坐标,我不明白我应该写什么,因为没有可以准备作为成员变量的键。
这是父 Geometry 类...
package info.metadude.trees.model.vienna;
import com.google.gson.annotations.SerializedName;
public class Geometry {
@SerializedName("type")
public String type;
// TODO: Prepare Coordinates class for GSON.
// @SerializedName("coordinates")
// public Coordinates coordinates;
}
... 和空的 Coordinates 类。
package info.metadude.trees.model.vienna;
public class Coordinates {
// TODO: No idea what should be defined here.
}
【问题讨论】:
-
我认为坐标本身不应该是一个类,而只是几何类中的一个双精度数组。或者您必须提供自己的序列化器和反序列化器。
标签: java arrays json deserialization gson