我喜欢omegastripes / VBA-JSON-parser,但我不知道如何解析以下json文件:https://coronavirus.ravenpack.com/data/1.3/country/US/panic.json
仅在提供的模块的测试子例程中更改URL时,出现错误“ JSON不包含行”。
有人在这样的结构上有经验吗?这个想法是将名称-值对提取到工作表的两列中。
Array---Object w/ name–value pair
---Object w/ name–value pair
...
Object
这对我有用:
Option Explicit
Sub returnResults()
Dim ret As String
ret = getData
Dim json As Object
Set json = parseJSON(ret)
Dim k As Variant
For Each k In json("results")
Debug.Print k("ts") & "|" & k("panic")
Next
End Sub
Function getData() As String
Dim httpServer As New XMLHTTP 'set reference to Microsoft WinHTTP Services
With httpServer
.Open "GET", "https://coronavirus.ravenpack.com/data/1.3/country/US/panic.json"
.setRequestHeader "Content-type", "application/json"
.send
Do: DoEvents: Loop Until .readyState = 4
getData = .responseText
End With
End Function
输出样本:
2020-05-21 00:00:00|3.42
2020-05-20 00:00:00|3.59
2020-05-19 00:00:00|3.26
2020-05-18 00:00:00|4.86
2020-05-17 00:00:00|3.96
2020-05-16 00:00:00|4.09
2020-05-15 00:00:00|4.27
2020-05-14 00:00:00|4.04
2020-05-13 00:00:00|3.56
2020-05-12 00:00:00|3.94
2020-05-11 00:00:00|7.15
2020-05-10 00:00:00|5.92
2020-05-09 00:00:00|3.8
2020-05-08 00:00:00|3.3