增加 {与"之间无意义空格的过滤
This commit is contained in:
		| @ -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) { | ||||
| 			// 是关键词 | ||||
|  | ||||
| @ -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) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user