Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve data from JSON

Status
Not open for further replies.

G12Consult

Programmer
May 12, 2016
77
0
0
AU
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:

Code:
 Private Sub GetCoordinates()
        Dim url As String = "[URL unfurl="true"]http://api.positionstack.com/v1/forward?access_key=be7ca3e5b82d0405a767ce25c13ceab4&query="[/URL] + 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
 
If you can edit the post, I recommend you remove the access_key value from the code block.


-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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top