limwei
04-02-2021, 12:57 AM
i am trying to get the fare required to travel from one point to another point by extracting the data "tr" from a json API under total_data but i cant seem to get it. i just started learning this vba thingy so sorry for the lack of knowledge if i said anything that isnt correct. Below you can find the function and the url i am requesting from.
This is my function:
Function PAS(origin, destination)
Dim strUrl As String
strUrl = "https://www.streetdirectory.com/api/?mode=journey&output=json&country=sg&q=" & origin & "%20to%20" & destination & "&methods=bustrain&vehicle=both&info=1&date=06/20/2021&time=01:38%20PM"
Set httpReq = CreateObject("MSXML2.XMLHTTP")
With httpReq
.Open "GET", strUrl, False
.Send
End With
Dim response As String
response = httpReq.ResponseText
Debug.Print response
Dim parsed As Dictionary
Set parsed = JsonConverter.ParseJson(response)
Dim dollar As Double
For Each leg In parsed("total_data")
dollar = dollar + leg("tr")
Next leg
PAS = dollar
End Function
The URL i am requesting from:
https://www.streetdirectory.com/api/?mode=journey&output=json&country=sg&q=629649%20to%20828732&methods=bustrain&vehicle=both&info=1&date=06/20/2021&time=01:38%20PM
This is my function:
Function PAS(origin, destination)
Dim strUrl As String
strUrl = "https://www.streetdirectory.com/api/?mode=journey&output=json&country=sg&q=" & origin & "%20to%20" & destination & "&methods=bustrain&vehicle=both&info=1&date=06/20/2021&time=01:38%20PM"
Set httpReq = CreateObject("MSXML2.XMLHTTP")
With httpReq
.Open "GET", strUrl, False
.Send
End With
Dim response As String
response = httpReq.ResponseText
Debug.Print response
Dim parsed As Dictionary
Set parsed = JsonConverter.ParseJson(response)
Dim dollar As Double
For Each leg In parsed("total_data")
dollar = dollar + leg("tr")
Next leg
PAS = dollar
End Function
The URL i am requesting from:
https://www.streetdirectory.com/api/?mode=journey&output=json&country=sg&q=629649%20to%20828732&methods=bustrain&vehicle=both&info=1&date=06/20/2021&time=01:38%20PM