update json tree
This commit is contained in:
parent
cd52bbb02b
commit
b6a27fffd5
@ -9,7 +9,7 @@ package tree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -88,7 +88,7 @@ func (g *Generate) init() error {
|
||||
fmt.Println(jsonKey, valueType, jsonValue, startIndex)
|
||||
// 创建节点, 并挂在到树上
|
||||
var newNode *Node
|
||||
if util.Array.In(g.currentNode.ValueType, []string{ValueTypeArray, ValueTypeMap}) >= 0 {
|
||||
if wrapper.ArrayType([]string{ValueTypeArray, ValueTypeMap}).Has(g.currentNode.ValueType) >= 0 {
|
||||
newNode = NewNode(jsonKey, jsonValue, valueType, g.currentNode)
|
||||
g.currentParentNode = g.currentNode
|
||||
g.currentParentNode.SonNodeList = append(g.currentParentNode.SonNodeList, newNode)
|
||||
@ -116,25 +116,26 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if charStr == KeywordDoubleQuote && !hasStart {
|
||||
// 第一次遇见双引号
|
||||
startIndex++
|
||||
hasStart = true
|
||||
continue
|
||||
}
|
||||
if charStr == KeywordDoubleQuote && hasStart {
|
||||
// 第二次遇见双引号,key探寻结束
|
||||
startIndex++
|
||||
break
|
||||
if charStr == KeywordDoubleQuote {
|
||||
if !hasStart {
|
||||
// 第一次遇见双引号
|
||||
startIndex++
|
||||
hasStart = true
|
||||
continue
|
||||
} else {
|
||||
// 第二次遇见双引号,key探寻结束
|
||||
startIndex++
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !hasStart {
|
||||
if util.Array.In(charStr, []string{
|
||||
if wrapper.ArrayType([]string{
|
||||
KeywordDoubleQuote,
|
||||
KeywordObjectStart,
|
||||
KeywordArrayStart,
|
||||
KeywordComma,
|
||||
}) >= 0 {
|
||||
}).Has(charStr) >= 0 {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
@ -181,21 +182,18 @@ func (g *Generate) getValueType(startIndex int) (string, int, error) {
|
||||
hasFindColon := false
|
||||
for startIndex < len(g.jsonDataByte) {
|
||||
charStr := string(g.jsonDataByte[startIndex])
|
||||
if !hasFindColon {
|
||||
if charStr == KeywordSpace {
|
||||
// 跳过空格
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
if charStr != KeywordSpace {
|
||||
// 非空格
|
||||
if charStr != KeywordColon {
|
||||
return "", startIndex, errors.New("value is invalid")
|
||||
}
|
||||
startIndex++
|
||||
hasFindColon = true
|
||||
break
|
||||
if charStr == KeywordSpace {
|
||||
// 跳过空格
|
||||
startIndex++
|
||||
continue
|
||||
} else {
|
||||
// 非空格
|
||||
if charStr != KeywordColon {
|
||||
return "", startIndex, errors.New("value is invalid")
|
||||
}
|
||||
startIndex++
|
||||
hasFindColon = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,13 +262,13 @@ func (g *Generate) getValue(startIndex int) (string, int, error) {
|
||||
continue
|
||||
}
|
||||
if !isStart {
|
||||
if util.Array.In(str, []string{KeywordArrayEnd, KeywordObjectEnd, KeywordComma}) >= 0 {
|
||||
if wrapper.ArrayType([]string{KeywordArrayEnd, KeywordObjectEnd, KeywordComma}).Has(str) >= 0 {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
}
|
||||
if isStart {
|
||||
if util.Array.In(str, []string{KeywordDoubleQuote, KeywordArrayEnd, KeywordObjectEnd, KeywordComma}) >= 0 {
|
||||
if wrapper.ArrayType([]string{KeywordDoubleQuote, KeywordArrayEnd, KeywordObjectEnd, KeywordComma}).Has(str) >= 0 {
|
||||
// 值的拼接已结束
|
||||
startIndex++
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user