语法错误:URL数组(VBA)

时间:2016-09-04 05:38:01

标签: vba parsing

我的代码正在运行 - 但现在我收到了#34;语法错误,"突出显示URL1, URL2, URL3等,我不知道为什么。我认为可能应该将urlArray切换为字符串,但事实并非如此。有什么想法吗?

这是我的完整代码:

Option Explicit

Sub getJSON()

Dim sheetCount As Integer, urlArray As Variant
sheetCount = 1

urlArray = Array(“URL1”, "URL2", "URL3", "URL4", "URL5")

Dim MyRequest As Object: Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim MyUrls: MyUrls = urlArray
Dim k As Long
Dim Json As Object

For k = LBound(MyUrls) To UBound(MyUrls)
    With MyRequest
        .Open "GET", MyUrls(k)
        .Send
        Set Json = JsonConverter.ParseJson(.ResponseText)
    Dim i As Long, p As Object
    For i = 1 To Json("prices").Count
        Set p = Json("prices")(i)
        Sheets("Sheet" & sheetCount).Cells(i, 1) = p("name")
        Sheets("Sheet" & sheetCount).Cells(i, 2) = p("cost")("fareType")
        Sheets("Sheet" & sheetCount).Cells(i, 9) = p("cost")("base")
        Sheets("Sheet" & sheetCount).Cells(i, 10) = p("cost")("perMinute")
        Next i
        End With
sheetCount = sheetCount + 1
Next
End Sub

我从这些网址解析的JSON代码采用以下格式:

{"id":1,"prices":[{"name":"expressTaxi","cost":{"base":"USD4.50","fareType":
"time_plus_distance","cancelFee":"USD10.00","minimumAmt":"USD8.00","perMinute":"USD1.50",
"perDistanceUnit":"USD3.00"}}]

1 个答案:

答案 0 :(得分:2)

您正在使用“而不是"在您的数组URL1中的第一个索引上,只需替换它们,您就会很好!

所以这样:

urlArray = Array("URL1", "URL2", "URL3", "URL4", "URL5")

而不是:

urlArray = Array(“URL1”, "URL2", "URL3", "URL4", "URL5")