修复基础对象解析获取值的BUG
This commit is contained in:
parent
7530e07e7a
commit
f760ab057a
@ -79,7 +79,7 @@ func (g *Generate) init() error {
|
||||
return err
|
||||
}
|
||||
// 获取值
|
||||
if jsonValue, err = g.getValue(startIndex); nil != err {
|
||||
if jsonValue, startIndex, err = g.getValue(startIndex); nil != err {
|
||||
return err
|
||||
}
|
||||
fmt.Println(jsonKey, valueType, jsonValue, startIndex)
|
||||
@ -102,6 +102,7 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
|
||||
if charStr == KeywordDoubleQuote && !hasStart {
|
||||
// 第一次遇见双引号
|
||||
startIndex++
|
||||
@ -114,6 +115,14 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
break
|
||||
}
|
||||
|
||||
if !hasStart {
|
||||
if charStr == KeywordDoubleQuote || charStr == KeywordObjectStart || charStr == KeywordArrayStart || charStr == KeywordComma {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
return "", startIndex, errors.New("parse key : format is invalid")
|
||||
}
|
||||
|
||||
if charStr == KeywordEscapeSymbol {
|
||||
// 转义符
|
||||
startIndex++
|
||||
@ -227,7 +236,7 @@ func (g *Generate) getValueType(startIndex int) (string, int, error) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:09 2023/3/30
|
||||
func (g *Generate) getValue(startIndex int) (string, error) {
|
||||
func (g *Generate) getValue(startIndex int) (string, int, error) {
|
||||
valArr := make([]string, 0)
|
||||
isStart := false
|
||||
for startIndex < len(g.jsonDataByte) {
|
||||
@ -262,7 +271,7 @@ func (g *Generate) getValue(startIndex int) (string, error) {
|
||||
valArr = append(valArr, str)
|
||||
startIndex++
|
||||
}
|
||||
return strings.Join(valArr, ""), nil
|
||||
return strings.Join(valArr, ""), startIndex, nil
|
||||
}
|
||||
|
||||
// isObject 整体是否为对象
|
||||
|
Loading…
Reference in New Issue
Block a user