Print specific data with Json perse

随声附和 提交于 2021-02-11 15:20:53

问题


This is json code (https://textsaver.flap.tv/lists/3ic4) and i am trying

Sub test()
Dim req As New MSXML2.XMLHTTP60
Dim URL As String, ws As Worksheet
Dim json As Object, r, r1 As String
URL = "https://www.nseindia.com/api/quote-equity?symbol=DIVISLAB"
With req
.Open "GET", URL, False
.send
Set json = JsonConverter.ParseJson(.responseText)
r = json("data")(1)("CH_OPENING_PRICE")
r1 = json("data")(1)("CH_CLOSING_PRICE")
End With

Debug.Print r
Debug.Print r1
End Sub

I want to print TEXT underbelow mentioned point. its in picture also highlighted in blue.

json>[data]>{1}>CH_OPENING_PRICE & CH_CLOSING_PRICE.

It will be more helpful if anyone suggest me any website or book for basic idea about trim text from nested json.


回答1:


First of all put json("data") in a variable:

   set data = json("data")
      'maybe you don't need the "set" keyword there, check documentation to your json library

Then iterate the data

For Each dataitem In data
    r = dataitem("CH_OPENING_PRICE")
    r1 = dataitem ("CH_CLOSING_PRICE")
    Debug.Print r
    Debug.Print r1
Next




来源:https://stackoverflow.com/questions/63098534/print-specific-data-with-json-perse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!