From 4629e31171996d30ebbd460bbfcaa78c879990bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 30 Mar 2023 14:32:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E7=9A=84JSON=E6=A0=91?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tree/generate.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tree/generate.go b/tree/generate.go index 322b27f..aa8b844 100644 --- a/tree/generate.go +++ b/tree/generate.go @@ -64,6 +64,7 @@ func (g *Generate) init() error { } g.root.ValueType = valueType + g.currentNode.ValueType = valueType for { if startIndex >= len(g.jsonDataByte) { @@ -83,6 +84,16 @@ func (g *Generate) init() error { return err } fmt.Println(jsonKey, valueType, jsonValue, startIndex) + // 创建节点, 并挂在到树上 + var newNode *Node + if g.currentNode.ValueType == ValueTypeArray || g.currentNode.ValueType == ValueTypeMap { + newNode = NewNode(jsonKey, jsonValue, valueType, g.currentNode) + g.currentParentNode = g.currentNode + g.currentParentNode.SonNodeList = append(g.currentParentNode.SonNodeList, newNode) + } else { + newNode = NewNode(jsonKey, jsonValue, valueType, g.currentParentNode) + } + g.currentNode = newNode } return nil }