key解析支持转义符的处理
This commit is contained in:
parent
047935c85c
commit
9bbd781a1f
@ -108,6 +108,16 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
||||
startIndex++
|
||||
break
|
||||
}
|
||||
|
||||
if charStr == KeywordEscapeSymbol {
|
||||
// 转义符
|
||||
startIndex++
|
||||
if startIndex >= len(g.jsonDataByte) {
|
||||
// 转义符后面没东西了
|
||||
return "", startIndex, errors.New("escape symbol without any data")
|
||||
}
|
||||
charStr = string(g.jsonDataByte[startIndex])
|
||||
}
|
||||
keyCharList = append(keyCharList, charStr)
|
||||
startIndex++
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
jsonData := `{"name": "zhang", "age":17}`
|
||||
jsonData := `{"n\\\\\\ame": "zhang", "age":17}`
|
||||
g, err := New(jsonData)
|
||||
if nil != err {
|
||||
fmt.Println(err.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user