Solved

how to read Json in VB 2010

Posted on 2015-01-13
15
121 Views
Last Modified: 2015-01-18
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
0
Comment
Question by:jellydeal
  • 6
  • 5
  • 4
15 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40546835
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40546840
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
 

Author Comment

by:jellydeal
ID: 40546879
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:jellydeal
ID: 40546880
I also have no idea how to implement json.net in vb 2010 express. I can see any references to it
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40546883
my article gives you the link to download it: https://json.codeplex.com/releases
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40546893
right mouse click Reference and select "Manage NuGet Packages". From there, search for it or plug in the url Eric posted
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40546910
were "nuget packages" fully supported back in VS 2010 express?
0
 

Author Comment

by:jellydeal
ID: 40546911
I cant find any package manager? If I could find the dll, I could manualy add it as a reference>?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40546915
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
 
LVL 33

Expert Comment

by:Big Monty
ID: 40546928
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40546934
>>If I could find the dll, I could manualy add it as a reference>?

Yes download it from CodePlex.
0
 

Author Comment

by:jellydeal
ID: 40547091
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40547142
have you looked at my article? it is all written in there
0
 

Accepted Solution

by:
jellydeal earned 0 total points
ID: 40547402
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
 

Author Closing Comment

by:jellydeal
ID: 40555995
I figured it out!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now