我正在尝试将json api转换为excel表.我尝试了不同的解析方法,但目前使用的是VBA-JSON(类似于VB-JSON但解析速度更快).到目前为止,我将它转换为Object.如果我是正确的话,这是一个集合.但是,将对象转换为表会花费大量时间.
以下是我的代码.在我正在使用的旧机器上,HTTP>字符串使用9s.解析对象需要花费14s.这些是可以接受的,但是循环在集合中经过一列(25k行)成本为30 + s.我需要大约8列从集合中获取,这将花费太长时间.我的i5机器需要的时间也一样长.
Dim ItemCount As Integer
Dim itemID() As Long
Function httpresp(URL As String) As String
Dim x As Object: Set x = CreateObject("MSXML2.XMLHTTP")
x.Open "GET", URL, False
x.send
httpresp = x.responseText
End Function
Private Sub btnLoad_Click()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = false
Dim URL As String: URL = "https://www.gw2shinies.com/api/json/item/tp"
Dim DecJSON As Object: Set DecJSON = JsonConverter.ParseJson(httpresp(URL))
ItemCount = DecJSON.Count
ReDim itemID(1 To ItemCount)
Range("A2:S25000").Clear 'clear range
For i = 1 To ItemCount
Cells(i …Run Code Online (Sandbox Code Playgroud)