English 中文(简体)
Jackson json : Crossersing a json web node by node
原标题:Jackson json : traversing a json tree node by node

我有多份含有json数据的文件,还有一米使用新的目标Mapper().readTree()方法,在Jackson parser将json数据 par到OM树。

现在我要说的是,我有两个红树——t1和t2。 每一树都有许多儿童节点,这反过来会有许多儿童节点。

What I d like to do is traverse the tree t1 node by node and compare every node in t1 with every node in t2. I know Jackson json parser allows me to query specific nodes, but how do I traverse an entire tree node by node?

问题回答

您可以简单地使用<条码>Json Node.iterator()方法,使节日的所有分母(达到您所需要的水平)。 您可以检查一下以下几类:<条码>Json Node.isArray或Json Node.isObject或任何其他类型,以便停止深层次的搜索。 你们所需要的一切都与trees transersal 有关。

如果你只是想比较一下t1和t2,那么你可以写成1. 当量(t2)。 我假定,t1和t2是Json Node型,采用了平等的方法。

 boolean NodesEqual(JsonNode n1, JsonNode n2) {
  if(n1.size()!=n2.size())return false;
  // ... other equality checks, like name, data type, etc
  for(int i=0;i<n.size();i++){
    JsonNode child1 = n1.get(i);
    JsonNode child2 = n2.get(i);
    if(!NodesEqual(child1,child2)) return false;
  } 
  return true;
 }

这是一种休养、如此庞大或深厚的文件,可能产生问题,但对于正常情况来说,这应当予以罚款。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签