Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

前端 未结 12 1085
旧巷少年郎
旧巷少年郎 2020-11-22 10:04

I know there are a few posts about Newtonsoft so hopefully this isn\'t exactly a repeat...I\'m trying to convert JSON data returned by Kazaa\'s API into a nice object of som

12条回答
  •  心在旅途
    2020-11-22 10:09

    Finally Get State Name From JSON

    Thankyou!

    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Net
    Imports Newtonsoft.Json
    Imports Newtonsoft.Json.Linq
    Imports System.collections.generic
    
    Public Module Module1
        Public Sub Main()
    
             Dim url As String = "http://maps.google.com/maps/api/geocode/json&address=attur+salem&sensor=false"
                Dim request As WebRequest = WebRequest.Create(url)
            dim response As WebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            dim reader As New StreamReader(response.GetResponseStream(), Encoding.UTF8)
              Dim dataString As String = reader.ReadToEnd()
    
            Dim getResponse As JObject = JObject.Parse(dataString)
    
            Dim dictObj As Dictionary(Of String, Object) = getResponse.ToObject(Of Dictionary(Of String, Object))()
            'Get State Name
            Console.WriteLine(CStr(dictObj("results")(0)("address_components")(2)("long_name")))
        End Sub
    End Module
    

提交回复
热议问题