VBA,数组哈希值

时间:2018-01-12 19:48:18

标签: arrays excel-vba hash vba excel

我有一个来自exi的api的json请求,我想转换它。

这就是我得到的:

{data:[{price: 3, amount:7},{price: 21, amount:16},{price: 18, amount:4}]}

我想将其转换为:

{data:[[3,7],[21,16],[18,4]]}

我该如何处理?

我正在做的就是抱歉:

text = DownloadTextFile("www../api/etc")
Set json = JsonConverter.ParseJson(text)

然后我想循环;

For j = 0 To 100
Range("h" & j) = json(data)(j)(1)
Next j

但是Range("h" & j) = json(data)(j)(1)当然不起作用,因为它不是一个数组。这就是为什么我想转换它。我不知道如何循环哈希并获得价格和金额数据。

我将使用该库并写在这里以防我遇到问题,谢谢!

1 个答案:

答案 0 :(得分:1)

Option Explicit

Sub Macro1()

    On Error Resume Next

    Dim Loc As Range
    Dim a1 As Range
    Dim a2 As Range
    Dim sht As Worksheet
    Dim shtIndx As Integer, rplc As String, rng1 As String, i As Integer

    shtIndx = ActiveSheet.Index
    rplc = "asdfghjklzxcvbnm"
    rng1 = "57001"

    For i = ActiveSheet.Index + 1 To Sheets.Count
      With ThisWorkbook.Worksheets(i)
          Set Loc = .Cells.Find(What:=rng1)
          Set a1 = Nothing
          If Not (Loc Is Nothing) Or Not (a2 Is Nothing) Then
              MsgBox "Found string in WS " & .Name
              Do Until Loc Is Nothing
                  '.Select                              ' Not really needed
                  '.Cells(Loc.Row, Loc.Column).Select   ' Not really needed
                  Loc.Value = rplc
                  If a1 Is Nothing Then
                      Set a1 = Application.InputBox("First Value?", "Obtain Range Object", Type:=8)
                      Set Loc = .UsedRange.FindNext(Loc)
                  Else
                      Set a2 = Application.InputBox("Second Value?", "Obtain Range Object", Type:=8)
                  End If
              Loop
          End If
      End With
    Next i

    For Each sht In ActiveWorkbook.Worksheets
      sht.Cells.Replace What:=rplc, Replacement:=rng1, _
      LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
      SearchFormat:=False, ReplaceFormat:=False
    Next sht

    Sheets(shtIndx).Select

End Sub