Json字符串检查VBA



我试图解析一个json文件,其中有一个(,)缺失的对象之间,使用VBA-JSON github项目(https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas),但它没有给出任何错误,并成功转换json excel我怎么能指出缺失(,)?

Json文件看起来像这样;-

{    
"hotel": "5-star"
"spa-available": true,
"restaurant-menu": [

{
"dish": "Pizza",
"order": 1,
"ketch-up": true,
"price": "25",
"extra-cheese": "yes"
},
{
"dish": "Burger",
"order": 2,
"ketch-up": true,
"price": "12",
"extra-cheese": "no"
}
]
}

我不知道验证器(除了JSONConverter似乎没有问题),所以这个方法利用http://json.parser.online.fr/:

中的解析器
Private Sub ValidateJSONByIE()
Dim jsontxt As String
jsontxt = OpenTxtFile("path of the JSON file")

Dim ieObj As Object
Set ieObj = CreateObject("InternetExplorer.Application")
Dim ieDoc As Object

ieObj.Visible = True 'Remove if do not need IE to be visible
ieObj.navigate "http://json.parser.online.fr/"
Do While ieObj.Busy Or ieObj.readyState <> 4
DoEvents
Loop

Set ieDoc = ieObj.Document

Dim inputEle As Object
Set inputEle = ieDoc.getElementById("eT")
inputEle.Value = jsontxt
inputEle.Click

Dim parseEle As Object
Set parseEle = ieDoc.getElementById("hW")

If InStr(parseEle.innerText, "error") <> 0 Then
Debug.Print "Error"
Else
Debug.Print "No Error"
End If

ieObj.Quit
Set ieObj = Nothing

End Sub
Private Function OpenTxtFile(argPath As String) As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim txtFile As Object
Set txtFile = FSO.OpenTextFile(argPath)

OpenTxtFile = txtFile.ReadAll

txtFile.Close
Set txtFile = Nothing
Set FSO = Nothing
End Function

最新更新