如何使用java将json对象键添加到一起?

时间:2014-06-30 16:13:54

标签: java json

例如,使用json对象:

{
"name": "flare",
 "children": [
  {
   "name": "analytics",
   "children": [
    {
     "name": "cluster",
     "children": [
      {"name": "AgglomerativeCluster", "size": 3938},
      {"name": "CommunityStructure", "size": 3812},
      {"name": "HierarchicalCluster", "size": 6714},
      {"name": "MergeEdge", "size": 743}
     ]
    },
    {
     "name": "graph",
     "children": [
      {"name": "BetweennessCentrality", "size": 3534},
      {"name": "LinkDistance", "size": 5731},
      {"name": "MaxFlowMinCut", "size": 7840},
      {"name": "ShortestPaths", "size": 5914},
      {"name": "SpanningTree", "size": 3416}
     ]
    },
    {
     "name": "optimization",
     "children": [
      {"name": "AspectRatioBanker", "size": 7074}
     ]
    }
   ]
  }
}

如何为子文件添加值(文件大小)并将其指定为父文件夹的值?例如,在上面的json对象中,将子文件大小的总和分配给" cluster"作为价值,而不是儿童'。

1 个答案:

答案 0 :(得分:0)

您可以使用Jackson Json processor Library和库来自定义Java对象中的Json。