shahin
Active Member
I've written a script to parse some json data from a webpage. In case of parsing an individual item and it's values, my script is doing fine. The problem is I can't create a loop to get them all . Any help on this will be a great relief for me. Thanks in advance.
This is exactly how the json data in that webpage look like:
The script I've tried with:
The result it produces:
Btw, the data gets update in a regular interval so the output may vary. However, the basic structure is as I've shown above.
This is exactly how the json data in that webpage look like:
Code:
[{"BTC":{"sellPrice":644999,"buyPrice":640601,"lastTradePrice":644900}},{"XRP":{"sellPrice":70.67,"buyPrice":70.5,"lastTradePrice":70.65}},{"NEO":{"sellPrice":8124,"buyPrice":7955,"lastTradePrice":8002}},{"GAS":{"sellPrice":2966.99,"buyPrice":2925,"lastTradePrice":2925}},{"ETH":{"sellPrice":59950,"buyPrice":59850,"lastTradePrice":60000}},{"XLM":{"sellPrice":28.38,"buyPrice":28.19,"lastTradePrice":28.39}}]
The script I've tried with:
Code:
Sub fetch_json_data()
Dim HTTP As New XMLHTTP60, res As Variant
With HTTP
.Open "GET", "https://bitbns.com/order/getTickerAll", False
.setRequestHeader "User-Agent", "Mozilla/5.0"
.send
res = .responseText
End With
[A1] = Split(Split(res, "{""")(1), """:")(0)
[B1] = Split(Split(Split(res, "BTC"":{")(1), "sellPrice"":")(1), ",")(0)
[C1] = Split(Split(Split(res, "BTC"":{")(1), "buyPrice"":")(1), ",")(0)
[D1] = Split(Split(Split(res, "BTC"":{")(1), "lastTradePrice"":")(1), "}}")(0)
End Sub
The result it produces:
Code:
BTC 644999 640601 644900
Btw, the data gets update in a regular interval so the output may vary. However, the basic structure is as I've shown above.