From 89f595c48aac972825c76aeb7fd081f717c2f11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 4 Jul 2022 19:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20{=E4=B8=8E"=E4=B9=8B?= =?UTF-8?q?=E9=97=B4=E6=97=A0=E6=84=8F=E4=B9=89=E7=A9=BA=E6=A0=BC=E7=9A=84?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lexical.go | 5 +++++ lexical_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lexical.go b/lexical.go index 394aaf3..33b1332 100644 --- a/lexical.go +++ b/lexical.go @@ -22,6 +22,7 @@ import ( // Date : 18:11 2022/7/4 func parseLexical(jsonData string) ([]lexicalNode, error) { jsonData = strings.ReplaceAll(strings.ReplaceAll(jsonData, "\n", ""), "\t", "") + // mt.Println(jsonData) if len(jsonData) < 2 { return nil, errors.New("input data is not json") } @@ -32,6 +33,10 @@ func parseLexical(jsonData string) ([]lexicalNode, error) { preChar := "-1" if len(lexicalList) > 0 { preChar = lexicalList[len(lexicalList)-1].Val + if preChar == objectLeftToken && currentChar == " " { + // 无意义的空格 + continue + } } if inputCharIsToken(currentChar, preChar) { // 是关键词 diff --git a/lexical_test.go b/lexical_test.go index 02145f7..d894b3b 100644 --- a/lexical_test.go +++ b/lexical_test.go @@ -30,6 +30,6 @@ func Test_parseLexical(t *testing.T) { } ] }` - jsonData = `{"name":"zhangsan","age":"18","extension":{"sex":"man","height":"180"},"teacher_list":[{"name":"t1","age":"11"},{"name":"t2","age":"12"}]}` + //jsonData = `{"name":"zhangsan","age":"18","extension":{"sex":"man","height":"180"},"teacher_list":[{"name":"t1","age":"11"},{"name":"t2","age":"12"}]}` parseLexical(jsonData) }