Retrieve data from JSON
Retrieve data from JSON
(OP)
I am trying to receive data from a json feed.
I can successfully perform the http request which gives me some json data like below:
jsonObject = {{
"data": [
{
"latitude": -20.025382,
"longitude": 143.314035,
"type": "address",
"name": "xxxx",
"number": "xxx",
"postal_code": "42111",
"street": "xxxx",
"confidence": 1,
...
But when I try to retrieve the latitude, it retrieves nothing.
Here is my code to perform the request and try to read the data:
Where am I going wrong?
Thanks
I can successfully perform the http request which gives me some json data like below:
jsonObject = {{
"data": [
{
"latitude": -20.025382,
"longitude": 143.314035,
"type": "address",
"name": "xxxx",
"number": "xxx",
"postal_code": "42111",
"street": "xxxx",
"confidence": 1,
...
But when I try to retrieve the latitude, it retrieves nothing.
Here is my code to perform the request and try to read the data:
CODE
Private Sub GetCoordinates() Dim url As String = "http://api.positionstack.com/v1/forward?access_key=be7ca3e5b82d0405a767ce25c13ceab4&query=" + txtAddressLine1.Text + "," + txtAddressLine2.Text + "," + txtAddressLine3.Text + "," + txtAddressLine4.Text + "," + txtAddressLine5.Text + "," + txtCity.Text + "," + txtPostcode.Text Dim request As HttpWebRequest Dim WebResponse As HttpWebResponse = Nothing Dim reader As StreamReader request = DirectCast(WebRequest.Create(url), HttpWebRequest) WebResponse = DirectCast(request.GetResponse(), HttpWebResponse) reader = New StreamReader(WebResponse.GetResponseStream()) Dim RawResponse = reader.ReadToEnd() Dim json As String = RawResponse Dim jsonObject As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(json) Session("Latitude") = CStr(jsonObject("latitude")) 'Session("Latitude") = jsonObject.SelectToken("data.latitude") End Sub
Where am I going wrong?
Thanks
RE: Retrieve data from JSON
-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom