【发布时间】:2021-12-15 04:06:54
【问题描述】:
这是我的代码,我尝试了很多搜索,但没有找到正确的解决方案,请在那里提供帮助。
Sub JnewCOP22()
Dim req As New MSXML2.XMLHTTP60
Dim URL As String, ws As Worksheet
Dim json As Object, r, r1 As String, i, j As Integer
URL = "https://www.nseindia.com/api/quote-equity?symbol=DRREDDY§ion=trade_info"
With req
.Open "GET", URL, False
.send
Set json = JsonConverter.ParseJson(.responseText)
r = json("securityWiseDP")("quantityTraded")
End With
MsgBox r
End Sub
API 数据 {"noBlockDeals":true,"bulkBlockDeals":[{"name":"Session I"},{"name":"Session II"}],"marketDeptOrderBook":{"totalBuyQuantity":0,"totalSellQuantity": 264,"bid":[{"price":0,"quantity":0},{"price":0,"quantity":0},{"price":0,"quantity":0},{ "price":0,"quantity":0},{"price":0,"quantity":0}],"ask":[{"price":4659.2,"quantity":264},{"price ":0,"quantity":0},{"price":0,"quantity":0},{"price":0,"quantity":0},{"price":0,"quantity": 0}],"tradeInfo":{"totalTradedVolume":1945164,"totalTradedValue":92498.58,"totalMarketCap":7713541.51,"ffmc":5659504.6195251,"impactCost":0.02},"valueAtRisk":{"securityVar":10.89 ,"indexVar":0,"varMargin":10.89,"extremeLossMargin":3.5,"adhocMargin":0,"applicableMargin":14.39}},"securityWiseDP":{"quantityTraded":1945164,"deliveryQuantity":417789, "deliveryToTradedQuantity":21.48,"seriesRemarks":null,"secWiseDelPosDate":"29-OCT-2021 EOD"}}
错误消息说错误解析 json Expecting ' {' or '[ '
【问题讨论】:
-
这是来自代码的实际json,还是您作为示例获得的这个json?检查代码中出现的实际值 .responseText
-
您可能需要先获取 cookie,请参阅 here
-
请告诉我在编码中要改变什么。
-
这是我想要从中获取值的实际 json。 @ChrisStrickland
-
我的意思是,我从那个 URL 获得了有效的 JSON,但是当我解析它时,它返回一个值。看到这张图片:i.imgur.com/1g8MGeI.png 我刚收到 421170。这就是为什么我认为有一些问题。您不太可能将有效的 JSON 传递给 JsonConverter 并使其响应该错误。所以第一步是 Debug.Print .responseText 看看它实际上说了什么,因为我看不出它怎么可能是有效的 JSON 并且你得到了那个结果。你的代码对我来说很好用。