Resolved JSON object as vb classes

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
152
Programming Experience
1-3
Hi,

Can anyone process this json into vb classes... this is what I have done so far!
JSON:
{
    "results" : [
        {
            "address_components" : [
                {
                    "long_name" : "1600",
                    "short_name" : "1600",
                    "types" : [ "street_number" ]
                },
                {
                    "long_name" : "Amphitheatre Pkwy",
                    "short_name" : "Amphitheatre Pkwy",
                    "types" : [ "route" ]
                },
                {
                    "long_name" : "Mountain View",
                    "short_name" : "Mountain View",
                    "types" : [ "locality", "political" ]
                },
                {
                    "long_name" : "Santa Clara County",
                    "short_name" : "Santa Clara County",
                    "types" : [ "administrative_area_level_2", "political" ]
                },
                {
                    "long_name" : "California",
                    "short_name" : "CA",
                    "types" : [ "administrative_area_level_1", "political" ]
                },
                {
                    "long_name" : "United States",
                    "short_name" : "US",
                    "types" : [ "country", "political" ]
                },
                {
                    "long_name" : "94043",
                    "short_name" : "94043",
                    "types" : [ "postal_code" ]
                }
            ],
            "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
            "geometry" : {
                "location" : {
                    "lat" : 37.4224764,
                    "lng" : -122.0842499
                },
                "location_type" : "ROOFTOP",
                "viewport" : {
                    "northeast" : {
                        "lat" : 37.4238253802915,
                        "lng" : -122.0829009197085
                    },
                    "southwest" : {
                        "lat" : 37.4211274197085,
                        "lng" : -122.0855988802915
                    }
                }
            },
            "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
            "plus_code": {
                "compound_code": "CWC8+W5 Mountain View, California, United States",
                "global_code": "849VCWC8+W5"
            },
            "types" : [ "street_address" ]
        }
    ],
        "status" : "OK"
}

VB Classes


VB.NET:
Class ValuePair
    Public Property value As Integer
    Public Property text As String
End Class

Class Element
    Public Property status As String
    Public Property duration As ValuePair
    Public Property distance As ValuePair
End Class

Class Row
    Public Property elements As Element()  'Array
End Class

Class Response
    Public Property status As String
    Public Property results As String() ' Array
    Public Property rows As Row() 'Array
End Class

Maybe there a tool to do it....as I wish to obtain the full address...
 
Last edited by a moderator:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,553
Location
Norway
Programming Experience
10+

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
152
Programming Experience
1-3
Hi , I found a website that does it...
But I also used the class object and then access the elements using an array like structure as follows... Not sure if its more efficient or than using classes other than the usual OOP advantages!

VB.NET:
Dim response = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Object)(content)
                    Me.tbResult.Text = response("status")
                    Me.tbAddress2.Text = response("results")(0)("formatted_address")   
                    Me.tbAddress3.Text = response("results")(0)("geometry")("location")("lat").ToString
                    Me.tbAddress4.Text = response("results")(0)("geometry")("location")("lng").ToString
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,553
Location
Norway
Programming Experience
10+
Was there a problem with the VS conversion?
 
Top Bottom