增加 {与"之间无意义空格的过滤

This commit is contained in:
白茶清欢 2022-07-04 19:03:15 +08:00
parent 9f78206f80
commit 89f595c48a
2 changed files with 6 additions and 1 deletions

View File

@ -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) {
// 是关键词

View File

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