2023-03-28 18:58:39 +08:00
|
|
|
// Package tree ...
|
|
|
|
//
|
|
|
|
// Description : tree ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2023-03-28 18:42
|
|
|
|
package tree
|
|
|
|
|
2023-03-28 23:56:13 +08:00
|
|
|
import "strings"
|
|
|
|
|
2023-03-28 18:58:39 +08:00
|
|
|
// New 生成一棵JSON树
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 18:42 2023/3/28
|
2023-03-28 23:56:13 +08:00
|
|
|
func New(jsonData string) *Generate {
|
|
|
|
jsonData = strings.TrimSpace(jsonData)
|
|
|
|
g := &Generate{
|
|
|
|
jsonData: jsonData,
|
|
|
|
}
|
|
|
|
if g.isArray() {
|
|
|
|
g.root = &Node{
|
|
|
|
IsVirtual: true,
|
|
|
|
Value: nil,
|
|
|
|
ValueType: "",
|
|
|
|
Key: "",
|
|
|
|
Show: false,
|
|
|
|
ShowKey: "",
|
|
|
|
AllowEdit: false,
|
|
|
|
AllowChangeType: false,
|
|
|
|
DefaultValue: nil,
|
|
|
|
ParentNode: nil,
|
|
|
|
PreBrotherNode: nil,
|
|
|
|
LastBrotherNode: nil,
|
|
|
|
SonNodeList: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:46 2023/3/28
|
|
|
|
type Generate struct {
|
|
|
|
root *Node
|
|
|
|
jsonData string
|
|
|
|
}
|
|
|
|
|
|
|
|
// isObject 整体是否为对象
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:51 2023/3/28
|
|
|
|
func (g *Generate) isObject() bool {
|
|
|
|
return strings.HasPrefix(g.jsonData, KeywordObjectStart)
|
|
|
|
}
|
|
|
|
|
|
|
|
// isArray 整体是否为数组
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 22:51 2023/3/28
|
|
|
|
func (g *Generate) isArray() bool {
|
|
|
|
return strings.HasPrefix(g.jsonData, KeywordArrayStart)
|
2023-03-28 18:58:39 +08:00
|
|
|
}
|