From 9bbd781a1f339f903ed65356f3a9e9e8d9206fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 30 Mar 2023 12:02:40 +0800 Subject: [PATCH] =?UTF-8?q?key=E8=A7=A3=E6=9E=90=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=BD=AC=E4=B9=89=E7=AC=A6=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tree/generate.go | 10 ++++++++++ tree/generate_test.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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())