修复 in 判断的BUG
This commit is contained in:
parent
4629e31171
commit
a1a1b1d2e0
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20220627070212-c590a0a1c216
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230211164227-256094968151
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330082619-662152cb682d
|
||||
github.com/Jeffail/gabs v1.4.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/smartystreets/goconvey v1.7.2
|
||||
|
4
go.sum
4
go.sum
@ -3,6 +3,10 @@ git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20220627070212-c590a0a1c216/go.mod
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220626081130-cbac0b676fb8/go.mod h1:G2/OKMbEn89d+YUXQtv9Nlh0LGg14pOqDnbOgBTTRXY=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230211164227-256094968151 h1:j537bRLQL1FlkdXTIaT9Ecjx5eogkPsGiTOWIEFQlc8=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230211164227-256094968151/go.mod h1:SyRTkOz6gxUVn3S/Qtkf+rhKV0I1ym8lwsT8YjggYFs=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330065032-faba0a5a9ea1 h1:u2FdNfcGvRmlKpuPBk2qvYenkZjinHY2PLu5Wmhka8A=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330065032-faba0a5a9ea1/go.mod h1:SyRTkOz6gxUVn3S/Qtkf+rhKV0I1ym8lwsT8YjggYFs=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330082619-662152cb682d h1:kMQZmkYBceHM3O7wiCelSADjTyOF3EBxXTX8fgZA+6c=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330082619-662152cb682d/go.mod h1:qeVsrMae8ljqzcsmI+lWPU/4Rdjb9cOt4oaDUNEf1Ck=
|
||||
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
|
||||
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||
|
@ -9,6 +9,7 @@ package tree
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -27,6 +28,7 @@ func New(jsonData string) (*Generate, error) {
|
||||
}
|
||||
g.root = NewVirtualNode()
|
||||
g.currentNode = g.root
|
||||
g.currentParentNode = g.root
|
||||
err := g.init()
|
||||
return g, err
|
||||
}
|
||||
@ -86,7 +88,7 @@ func (g *Generate) init() error {
|
||||
fmt.Println(jsonKey, valueType, jsonValue, startIndex)
|
||||
// 创建节点, 并挂在到树上
|
||||
var newNode *Node
|
||||
if g.currentNode.ValueType == ValueTypeArray || g.currentNode.ValueType == ValueTypeMap {
|
||||
if util.Array.In(g.currentNode.ValueType, []string{ValueTypeArray, ValueTypeMap}) >= 0 {
|
||||
newNode = NewNode(jsonKey, jsonValue, valueType, g.currentNode)
|
||||
g.currentParentNode = g.currentNode
|
||||
g.currentParentNode.SonNodeList = append(g.currentParentNode.SonNodeList, newNode)
|
||||
@ -104,11 +106,11 @@ func (g *Generate) init() error {
|
||||
//
|
||||
// Date : 11:36 2023/3/29
|
||||
func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
keyCharList := []string{}
|
||||
keyCharList := make([]string, 0)
|
||||
hasStart := false
|
||||
for startIndex < len(g.jsonDataByte) {
|
||||
charStr := string(g.jsonDataByte[startIndex])
|
||||
if charStr == KeywordSpace {
|
||||
if charStr == KeywordSpace && !hasStart {
|
||||
// 跳过空格
|
||||
startIndex++
|
||||
continue
|
||||
@ -127,7 +129,12 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
}
|
||||
|
||||
if !hasStart {
|
||||
if charStr == KeywordDoubleQuote || charStr == KeywordObjectStart || charStr == KeywordArrayStart || charStr == KeywordComma {
|
||||
if util.Array.In(charStr, []string{
|
||||
KeywordDoubleQuote,
|
||||
KeywordObjectStart,
|
||||
KeywordArrayStart,
|
||||
KeywordComma,
|
||||
}) >= 0 {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
@ -252,18 +259,18 @@ func (g *Generate) getValue(startIndex int) (string, int, error) {
|
||||
isStart := false
|
||||
for startIndex < len(g.jsonDataByte) {
|
||||
str := string(g.jsonDataByte[startIndex])
|
||||
if str == KeywordSpace {
|
||||
if str == KeywordSpace && !isStart {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
if !isStart {
|
||||
if str == KeywordArrayEnd || str == KeywordObjectEnd || str == KeywordComma {
|
||||
if util.Array.In(str, []string{KeywordArrayEnd, KeywordObjectEnd, KeywordComma}) >= 0 {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
}
|
||||
if isStart {
|
||||
if str == KeywordDoubleQuote || str == KeywordArrayEnd || str == KeywordObjectEnd || str == KeywordComma {
|
||||
if util.Array.In(str, []string{KeywordDoubleQuote, KeywordArrayEnd, KeywordObjectEnd, KeywordComma}) >= 0 {
|
||||
// 值的拼接已结束
|
||||
startIndex++
|
||||
break
|
||||
@ -275,6 +282,7 @@ func (g *Generate) getValue(startIndex int) (string, int, error) {
|
||||
break
|
||||
} else {
|
||||
startIndex++
|
||||
isStart = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user