how to read Json in VB 2010

HI,
Im struggling to get the correct syntax to read a field in my json,

heres my json

{  
  "results":[  
    {  
      "address_components":[  
        {  
          "long_name":"NG18 4YP",
          "short_name":"NG18 4YP",
          "types":[  
            "postal_code"
          ]
        },
        {  
          "long_name":"Mansfield",
          "short_name":"Mansfield",
          "types":[  
            "locality",
            "political"
          ]
        },
        {  
          "long_name":"Mansfield",
          "short_name":"Mansfield",
          "types":[  
            "postal_town"
          ]
        },
        {  
          "long_name":"Nottinghamshire",
          "short_name":"Nottinghamshire",
          "types":[  
            "administrative_area_level_2",
            "political"
          ]
        },
        {  
          "long_name":"United Kingdom",
          "short_name":"GB",
          "types":[  
            "country",
            "political"
          ]
        }
      ],
      "formatted_address":"Mansfield, Mansfield, Nottinghamshire NG18 4YP, UK",
      "geometry":{  
        "bounds":{  
          "northeast":{  
            "lat":53.135115,
            "lng":-1.1843116
          },
          "southwest":{  
            "lat":53.1334688,
            "lng":-1.1865058
          }
        },
        "location":{  
          "lat":53.1343937,
          "lng":-1.1849156
        },
        "location_type":"APPROXIMATE",
        "viewport":{  
          "northeast":{  
            "lat":53.1356408802915,
            "lng":-1.184059719708498
          },
          "southwest":{  
            "lat":53.1329429197085,
            "lng":-1.186757680291502
          }
        }
      },
      "types":[  
        "postal_code"
      ]
    }
  ],
  "status":"OK"
}

Open in new window


I want the Lat & Lng values from the location_type":"APPROXIMATE", section??
 Heres my Code:

       
Dim result = JsonConvert.DeserializeObject(x)
        Dim lat
        com = result("results")("approximate")("lat")

Open in new window


thanks
jellydealAsked:
Who is Participating?
 
jellydealConnect With a Mentor Author Commented:
Hi,

thanks guys, I did look, but couldn't get it to work.
I did figure it out the , the JSON reference i needed WAS:
com = result("results")(0)("geometry")("location")("lat")

THANKS ANYWAY!
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
have you thought about using json.net?

once you have your class objects defined, it makes it a lot easier in working with them and accessing all of the data
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
jellydealAuthor Commented:
hi,

Ive spen all day just getting the right references installed etc ;)
Im happy using 'Newtonsoft.Json', I just dont know how to reference the json itself.

Using this Json and this code It works :
{'books':[{'title':'HarryPotter','pages':'134'}]}
Console.WriteLine(result("books")(0)("title") & " - " & result("books")(0)("pages"))

I jusy dont know how to structure the results line to access the other data
0
 
jellydealAuthor Commented:
I also have no idea how to implement json.net in vb 2010 express. I can see any references to it
0
 
Éric MoreauSenior .Net ConsultantCommented:
my article gives you the link to download it: https://json.codeplex.com/releases
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
right mouse click Reference and select "Manage NuGet Packages". From there, search for it or plug in the url Eric posted
0
 
Éric MoreauSenior .Net ConsultantCommented:
were "nuget packages" fully supported back in VS 2010 express?
0
 
jellydealAuthor Commented:
I cant find any package manager? If I could find the dll, I could manualy add it as a reference>?
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
good point Eric, I don't believe they were.

You'll need to download it, then add a reference. Look at the installation doc on the web site for specifics
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
I'm going to be offline for a bit, hopefully Eric can guide you the rest of the way. I'll check back later and offer any insights if needed
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>If I could find the dll, I could manualy add it as a reference>?

Yes download it from CodePlex.
0
 
jellydealAuthor Commented:
HI.. Ive decided to download visual studio 2013, this has the package manager..
Could you possibly supply a sample of the .net method of getting the data from json?
0
 
Éric MoreauSenior .Net ConsultantCommented:
have you looked at my article? it is all written in there
0
 
jellydealAuthor Commented:
I figured it out!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.