Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON String to JSON Object

Tags:

json

vb.net

I have a JSON response from a web service that I need to be converted to an object then to an array. My response is similar to the one below:

  {"status":{"error":"NO","code":"200","description":"none","message":"Request ok"},"geolocation":{"lat":"38.89515","lng":"-77.0310"},"stations":[{"country":"United States","regPrice":"0.00","midPrice":"0.00","prePrice":"0.00","streetAddress":"1401, I St NW","ID":"1900","lat":"38.901440","lng":"-77.032127","stationName":"Shell","logo":"http:\/\/www.nyneaxis.com\/logo\/stations\/noLogo.png","state":"District of Columbia","city":"Washington D.C.","regDate":null,"midDate":null,"preDate":null,"distance":"0.7"},{"country":"United States","regPrice":"0.00","midPrice":"0.00","prePrice":"0.00","streetAddress":"2116-2150, M St NW","ID":"13029","lat":"38.905201","lng":"-77.048103","stationName":"Exxon","logo":"http:\/\/www.nyneaxis.com\/logo\/stations\/noLogo.png","state":"District of Columbia","city":"Washington D.C.","regDate":null,"midDate":null,"preDate":null,"distance":"1.9"}]}

I am doing this is VB.NET within a console for now. Basically I am trying to create a simple way to test my API calls and output the information. What I am trying to accomplish is having to loop through the JSON array and list the stations. I have never done this in VB.NET before and would like some help. I have been reading about deserialization but do not understand it.

like image 585
Brandon Wilson Avatar asked Jan 18 '12 02:01

Brandon Wilson


2 Answers

You can use Json.NET

Dim ThisToken as Token = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Token)(JSonString)
like image 146
Daria Trainor Avatar answered Nov 15 '22 09:11

Daria Trainor


There's a good library for .NET called Json.NET that's useful for doing this kind of stuff http://json.codeplex.com/

there are a bunch of examples, mostly C# though.

like image 33
Keith Nicholas Avatar answered Nov 15 '22 10:11

Keith Nicholas