簡體   English   中英

VBA excel json 字符串到雙重轉換不起作用

[英]VBA excel json string to double conversion not working

我收到 json 響應,但無法將其轉換為雙精度。 function 忽略小數位(逗號)。

這是我的功能:

Public Function DownloadDataFromURL(url As String) As String
    Set Myrequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    Myrequest.Open "GET", url
    Myrequest.send
    Dim WebResponse As String
    WebResponse = Myrequest.responseText
    DownloadDataFromURL = WebResponse
End Function

Function getlatestPrice()
   Dim apiKey As String
   Dim latestPriceUrl As String
   Dim result As Double

    apiKey = "xyz"
    latestPriceUrl = "https://cloud.iexapis.com/stable/stock/aapl/quote/latestPrice?token="

    Dim url As String
    Dim data As String

    url = latestPriceUrl + apiKey
    data = DownloadDataFromURL(url)
    Debug.Print data

    result = CDbl(data)

    Debug.Print result

End Function

調試 output 給了我:

351.69

35169

為什么小數點不見了?

這似乎是當地的事情。 不確定如何為具有不同語言環境的用戶提供與國際無關的保存解決方案。

適用於使用逗號而不是點的國家/地區的解決方案:

result = CDbl(Replace(data, ".", ","))

這行得通

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM