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