Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Retrieve data from JSON

Retrieve data from JSON

Retrieve data from JSON

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:


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?


RE: Retrieve data from JSON

If you can edit the post, I recommend you remove the access_key value from the code block.

Microsoft SQL Server MVP
My Blogs
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close