Я пытаюсь получить данные с веб-сайта 'https://api.iextrading.com/1.0/stock/aapl/financials' на листе Excel (первоначально из https://iextrading.com/developer/docs/#financials). Я смог получить данные из' https://api.iextrading.com/1.0/stock/aapl/chart/1y', используя мой кодЯ пытался изменить его для страницы финансовых данных, но застрял, потому что не могу понять, как получить доступ к массиву в объекте, мой массив в настоящее время возвращает длину 2, то есть «символ» и «финансы».
Вот мой код:
'write to ws
Dim ws As Worksheet
Set ws = Sheets("Ratios")
Dim ticker As String
ticker = ws.Range("P7").Value
Dim lastrow As Integer
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).row
'clear range
ws.Range("A1:L" & lastrow).Clear
'array col headers
Dim myarray As Variant
myarray = Array("reportDate", "grossProfit", "costOfRevenue", "operatingRevenue", "totalRevenue", "operatingIncome", "netIncome", "researchAndDevelopment", "operatingExpense", "currentAssets", "totalAssets", "totalLiabilities", "currentCash", "currentDebt", "totalCash", "totalDebt", "shareholderEquity", "cashChange", "cashFlow", "operatingGainsLosses")
arrsize = UBound(myarray) - LBound(myarray) + 1
Dim rngTarget As Range
Set rngTarget = ws.Range(Cells(1, 1), Cells(1, arrsize))
rngTarget = myarray
'send web requests for API data
u = "https://api.iextrading.com/1.0/stock/aapl/financials"
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "Get", u
MyRequest.Send
'parse Json
Dim json As Object
Set json = JsonConverter.ParseJson(MyRequest.ResponseText)
'get # of objects in Array
Dim arraylen As Integer
arraylen = json.Count
MsgBox (arraylen)
'loop through elements
Dim elements As Variant
Dim x, y, r As Integer
r = 2
y = 1
x = 1
While x < arraylen + 1
For Each element In myarray
ws.Cells(r, y).Value = json(x)(element)
y = y + 1
Next element
y = 1
x = x + 1
r = r + 1
Wend
End Sub
Я также получаю несоответствие типов относительно json (x) (элемент).
Что я могу добавить в свой код такчто я могу получить доступ к массиву внутри объекта 'financials'?