繁体   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