如何从反序列化的JSON的内部类中获取值?

时间:2014-07-18 18:13:14

标签: json vb.net google-maps

我正在尝试从Google Geocode API获取lat和lng值。我使用parse google maps geocode json response to object using Json.Net的vb翻译设置了类。我可以访问状态和顶级结果,但我似乎无法访问结果的子项,即使我将鼠标悬停在结果上并打开加号时数据显示在调试模式中。

如何从反序列化的json的内部类中获取值? 设置decLat和decLon的行说“几何不是Systems.Array的成员”

Dim result = New System.Net.WebClient().DownloadString(Request.ToString)
                        Response = JsonConvert.DeserializeObject(Of GoogleGeoCodeResponse)(result)
                        If Response.status = "OK" Then
                            decLat = Response.results.geometry.location.lat
                            decLon = Response.results.geometry.location.lng



 Public Class GoogleGeoCodeResponse

        Public Property status() As String
            Get
                Return m_status
            End Get
            Set(value As String)
                m_status = Value
            End Set
        End Property
        Private m_status As String
        Public Property results() As results()
            Get
                Return m_results
            End Get
            Set(value As results())
                m_results = Value
            End Set
        End Property
        Private m_results As results()

    End Class

    Public Class results
        Public Property formatted_address() As String
            Get
                Return m_formatted_address
            End Get
            Set(value As String)
                m_formatted_address = Value
            End Set
        End Property
        Private m_formatted_address As String
        Public Property geometry() As Geometry
            Get
                Return m_geometry
            End Get
            Set(value As Geometry)
                m_geometry = Value
            End Set
        End Property
        Private m_geometry As Geometry
        Public Property types() As String()
            Get
                Return m_types
            End Get
            Set(value As String())
                m_types = Value
            End Set
        End Property
        Private m_types As String()
        Public Property address_components() As address_component()
            Get
                Return m_address_components
            End Get
            Set(value As address_component())
                m_address_components = Value
            End Set
        End Property
        Private m_address_components As address_component()
    End Class

    Public Class geometry
        Public Property location_type() As String
            Get
                Return m_location_type
            End Get
            Set(value As String)
                m_location_type = Value
            End Set
        End Property
        Private m_location_type As String
        Public Property location() As location
            Get
                Return m_location
            End Get
            Set(value As location)
                m_location = Value
            End Set
        End Property
        Private m_location As location
    End Class

    Public Class location
        Public Property lat() As Decimal
            Get
                Return m_lat
            End Get
            Set(value As Decimal)
                m_lat = value
            End Set
        End Property
        Private m_lat As String
        Public Property lng() As Decimal
            Get
                Return m_lng
            End Get
            Set(value As Decimal)
                m_lng = value
            End Set
        End Property
        Private m_lng As String
    End Class

    Public Class address_component
        Public Property long_name() As String
            Get
                Return m_long_name
            End Get
            Set(value As String)
                m_long_name = Value
            End Set
        End Property
        Private m_long_name As String
        Public Property short_name() As String
            Get
                Return m_short_name
            End Get
            Set(value As String)
                m_short_name = Value
            End Set
        End Property
        Private m_short_name As String
        Public Property types() As String()
            Get
                Return m_types
            End Get
            Set(value As String())
                m_types = Value
            End Set
        End Property
        Private m_types As String()
    End Class

0 个答案:

没有答案