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) }