Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
反转JSON请求的输出_Json_Excel_Vba_Web Scraping - Fatal编程技术网

反转JSON请求的输出

反转JSON请求的输出,json,excel,vba,web-scraping,Json,Excel,Vba,Web Scraping,我已经编写了一个发送JSON请求的宏 Sub getPrices() Dim strURL As String, strJSON As String, strTicker As String, strCurrency As String, strLength As String Dim i As Integer Dim i2 As Integer Dim http As Object Dim JSON As Object, Item As Object Dim LastColumn As Lo

我已经编写了一个发送JSON请求的宏

Sub getPrices()

Dim strURL As String, strJSON As String, strTicker As String, strCurrency As String, strLength As String
Dim i As Integer
Dim i2 As Integer
Dim http As Object
Dim JSON As Object, Item As Object
Dim LastColumn As Long
Dim lastrow As Long
With ActiveSheet
    LastColumn = .Cells(9, .Columns.Count).End(xlToLeft).Column
    lastrow = .Cells(Rows.Count, 2).End(xlUp).Row
End With


For x = 10 To lastrow

strTicker = Cells(x, 2).Value
strCurrency = Cells(6, 2).Value
strLength = Cells(5, 2).Value
strURL = "https://min-api.cryptocompare.com/data/histoday?fsym=" & strTicker & "&tsym=" & strCurrency & "&limit=" & strLength & "&aggregate=3&e=CCCAGG"

Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", strURL, False
http.Send
strJSON = http.ResponseText
i = 3

Set JSON = JsonConverter.ParseJson(strJSON)
For Each Item In JSON("Data")
Cells(x, i).Value = Item("close")
i = i + 1

Next
Next

End Sub
这种JSON请求的一个示例是以下输出

宏获取数据的方式使今天的数据位于LastColumn中。 我在Excel中的数据库存在的问题是,所有补充数据都以相反的方式存储,现在可以在A列中找到。我需要对齐数据。由于文件的大小,理想情况下,我不想使用匹配和索引公式。如何重新写入宏,使数据从最近-->旧而不是旧-->最近生成


提前感谢,

您可以向后循环集合,
JSON(“数据”)
。在此简化示例中:

代码:

Option Explicit

Public Sub getPrices()

    Dim strURL As String, strJSON As String, http As Object, JSON As Object, item As Long

    strURL = "https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=USD&limit=60&aggregate=3&e=CCCAGG"

    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", strURL, False
    http.Send
    strJSON = http.ResponseText

    Set JSON = JsonConverter.ParseJson(strJSON)

    For item = JSON("Data").Count To 1 Step -1   'JSON("Data")(item) <== dictionary
        Debug.Print JSON("Data")(item)("close")
    Next item

End Sub
选项显式
公共分包价格()
Dim strURL为字符串,strJSON为字符串,http为对象,JSON为对象,项为长
strURL=”https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=USD&limit=60&aggregate=3&e=CCCAGG"
设置http=CreateObject(“MSXML2.XMLHTTP”)
http.Open“GET”,strURL,False
http.Send
strJSON=http.ResponseText
Set JSON=JsonConverter.ParseJson(strJSON)

对于item=JSON(“Data”).Count到1步骤-1'JSON(“Data”)(item)我理解您想要的是恢复列中的排序顺序。现在,输出从第3列开始

尝试更改:

i = 3

Set JSON = JsonConverter.ParseJson(strJSON)
For Each Item In JSON("Data")
Cells(x, i).Value = Item("close")
i = i + 1
致:

Set JSON = JsonConverter.ParseJson(strJSON)
i = JSON("Data").Count + 2

For Each Item In JSON("Data")
Cells(x, i).Value = Item("close")
i = i - 1