完成简版value值获取
This commit is contained in:
@ -55,6 +55,7 @@ func (g *Generate) init() error {
|
||||
jsonKey string
|
||||
err error
|
||||
valueType string
|
||||
jsonValue string
|
||||
)
|
||||
|
||||
// 获取类型
|
||||
@ -77,7 +78,11 @@ func (g *Generate) init() error {
|
||||
if valueType, startIndex, err = g.getValueType(startIndex); nil != err {
|
||||
return err
|
||||
}
|
||||
fmt.Println(jsonKey, valueType, startIndex)
|
||||
// 获取值
|
||||
if jsonValue, err = g.getValue(startIndex); nil != err {
|
||||
return err
|
||||
}
|
||||
fmt.Println(jsonKey, valueType, jsonValue, startIndex)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -217,6 +222,49 @@ func (g *Generate) getValueType(startIndex int) (string, int, error) {
|
||||
return keyValType, startIndex, nil
|
||||
}
|
||||
|
||||
// getValue 获取JSON值
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 12:09 2023/3/30
|
||||
func (g *Generate) getValue(startIndex int) (string, error) {
|
||||
valArr := make([]string, 0)
|
||||
isStart := false
|
||||
for startIndex < len(g.jsonDataByte) {
|
||||
str := string(g.jsonDataByte[startIndex])
|
||||
if str == KeywordSpace {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
if !isStart {
|
||||
if str == KeywordArrayEnd || str == KeywordObjectEnd || str == KeywordComma {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
}
|
||||
if isStart {
|
||||
if str == KeywordDoubleQuote || str == KeywordArrayEnd || str == KeywordObjectEnd || str == KeywordComma {
|
||||
// 值的拼接已结束
|
||||
startIndex++
|
||||
break
|
||||
}
|
||||
}
|
||||
if str == KeywordDoubleQuote {
|
||||
if isStart {
|
||||
startIndex++
|
||||
break
|
||||
} else {
|
||||
startIndex++
|
||||
continue
|
||||
}
|
||||
}
|
||||
isStart = true
|
||||
valArr = append(valArr, str)
|
||||
startIndex++
|
||||
}
|
||||
return strings.Join(valArr, ""), nil
|
||||
}
|
||||
|
||||
// isObject 整体是否为对象
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
Reference in New Issue
Block a user