1.方式1: Iterator 方式,break跳出循环体
Iterator<JsonNode> it = laneDividerJson.elements();
while (it.hasNext()) {
String geom = it.next().get(GEOM).asText();
try {
LineString lineStr = (LineString) READER.read(geom);
if (lineStr.intersects(line)) {
exist.set(true);
break;
}
} catch (ParseException ex) {
LOGGER.error(ex.toString());
}
}
2.foreach方式
Map<String, JsonNode> boundarySMap = new HashMap<>();
jsonNode.fields().forEachRemaining(json -> {
JsonNode boundaryJson = json.getValue();
String fDivId = json.get("divId").asText();
boundarySMap.put(fDivId, boundaryJson);
});
该博客介绍了两种方法处理JSON数据,包括使用Iterator遍历并检查几何对象是否相交,以及使用foreach循环遍历JSON节点并存储特定信息。主要涉及JSON解析、地理空间操作及异常处理。
531

被折叠的 条评论
为什么被折叠?



