diff --git a/tree/generate.go b/tree/generate.go index afd8ef3..1d1a99c 100644 --- a/tree/generate.go +++ b/tree/generate.go @@ -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++ } diff --git a/tree/generate_test.go b/tree/generate_test.go index a124fa3..c7e118b 100644 --- a/tree/generate_test.go +++ b/tree/generate_test.go @@ -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())