由于工作关系,需要生成Json文件的配置,但vba使用dll实在太麻烦了,换了台电脑又需要重新引用,所以决定写Json的解析。
第一步:将字符串格式化。
思路:逐个字符判断该字符所属的类型,期望能将不同格式的Json字符串修改为统一格式的字符串。
将Json字符串中,空格、回车、TAB、换行符这几种没任何意义的字符删除。
Function StringToJson(st)
Dim i As Integer, ThisChar As String, NextChar As String, LastChar As String
Dim isInString As Boolean, OutPutStr As String
isInString = False
OutPutStr = ""
For i = 1 To Len(st)
ThisChar = Mid(st, i, 1)
NextChar = Mid(st, i + 1, 1)
Select Case ThisChar
Case """"
isInString = Not isInString
OutPutStr = OutPutStr & ThisChar
Case " "
LastChar = Mid(st, i - 1, 1)
If isInString = True Then
Out