优化自动生成json #3
@ -108,6 +108,16 @@ func (g *Generate) getKey(startIndex int) (string, int, error) {
|
|||||||
startIndex++
|
startIndex++
|
||||||
break
|
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)
|
keyCharList = append(keyCharList, charStr)
|
||||||
startIndex++
|
startIndex++
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
jsonData := `{"name": "zhang", "age":17}`
|
jsonData := `{"n\\\\\\ame": "zhang", "age":17}`
|
||||||
g, err := New(jsonData)
|
g, err := New(jsonData)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user