[英]Java - Tree Structure to JSON object
I have a tree structure modeled on the following template: https://github.com/gt4dev/yet-another-tree-structure/blob/master/java/src/com/tree/TreeNode.java 我有一个基于以下模板的树结构: https : //github.com/gt4dev/yet-another-tree-structure/blob/master/java/src/com/tree/TreeNode.java
I'd like to dump the entire tree into a JSON object. 我想将整个树转储到JSON对象中。 I have looked into using Jackson but I have a hard time finding adequate usage examples for this particular task.
我已经研究过使用Jackson,但是很难找到适合此特定任务的用法示例。
EDIT: I should have been clearer that what I'm looking for is a JSON file that has the same structure as the original tree, as such what I'm looking for is something like: 编辑:我应该更清楚我正在寻找的是一个与原始树具有相同结构的JSON文件,因此我正在寻找的是这样的:
{
"root": data {
"child 1": "data child 1",
"child 2": "data child 2" {
"child of child 2": "data..."
and so on... 等等...
JSON is a string format - a linear one. JSON是一种字符串格式-一种线性格式。
A tree is not a linear data type. 树不是线性数据类型。
With these, you need to decide on how a tree looks like as a string. 有了这些,您需要确定一棵树看起来像一个字符串的样子。
You can try: 你可以试试:
"A(B(E,F),C(G,H))"
"A(B(E,F),C(G,H))"
["A", "B", C"]
["A", "B", C"]
[{"node":"A","children":["B","C"]},{"node":"B","children":["E","F"]}]
[{"node":"A","children":["B","C"]},{"node":"B","children":["E","F"]}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.