我正在尝试遍历下面的JSON文本。问题是我不确定如何在Java中从坐标路径检索出坐标数组,格式为lon/lat。我已经包含了一个我正在尝试解析的JSON字符串,但是我不确定如何使用Jackson函数遍历到数组中。
坐标
坐标
"coordinates": {
"type": "Point",
"coordinates": [-82.3248262, 29.6516344]
Java 代码
if(root.path("coordinates").path("coordinates").isArray() &&
root.path("coordinates").path("coordinates") != null) {
lat = root.path("coordinates").path("coordinates").get(1).asText();
lon = root.path("coordinates").path("coordinates").get(0).asText();
}
if
语句永远不会为真,因为path()
方法返回的是MissingNode
对象而不是null。 - Avihoo Mamka