0
我試圖通過Jsonnode循環,但是根jsonNode正在複製數據。 試圖找出,但不知道我錯過了這個問題。將嘗試解釋下面的問題。試圖循環通過JsonNode,但根jsonNode正在複製數據
我要Jackson API。
的Json塊是:
{ 「查詢」:[
{
"id": "keyword",
"values": [
"test"
]
},{
"id": "include",
"values": [
false
]
}
]
}
我的Java代碼塊是迭代器FIELDNAMES = root.fieldNames(); 而(fieldNames.hasNext()){
String fieldName = fieldNames.next();
if (fieldName.equalsIgnoreCase("queries")) {
nameNode =root.get(fieldName);
}
JsonNode nameNode = root.get("queries");
for (JsonNode node : nameNode) {
JsonNode elementId = node.path("id").asText();
if (!elementId.isEmpty() && elementId.equalsIgnoreCase("include")) {
check = true;
include = node;
}
}
When debug comes to line for (JsonNode node : nameNode) { , node value is "id": "keyword", "values": [ "test" ] and nameNode is the json shown above but when it comes to next line which is " node.path("id").asText();"
名稱節點變量追加 「ID」: 「關鍵字」, 「值」:[ 「測試」] 2倍。
現在JSON是與「id」:「關鍵字」,「值」:[「測試」]附加2倍,並給出concurrentModificationException的原始JSON。
謝謝。完美解決方案 – Rahul