Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET JSON
I want to parse one json in c#.
Json File
 
Now to parse it i developed one another class to desirealize it.
GoogleResponse.cs
namespace Example
{
 
    public class AddressComponent
    {
 
        [JsonProperty("long_name")]
        public string LongName { get; set; }
 
        [JsonProperty("short_name")]
        public string ShortName { get; set; }
 
        [JsonProperty("types")]
        public string[] Types { get; set; }
    }
 
    public class Northeast
    {
 
        [JsonProperty("lat")]
        public double Lat { get; set; }
 
        [JsonProperty("lng")]
        public double Lng { get; set; }
    }
 
    public class Southwest
    {
 
        [JsonProperty("lat")]
        public double Lat { get; set; }
 
        [JsonProperty("lng")]
        public double Lng { get; set; }
    }
 
    public class Bounds
    {
 
        [JsonProperty("northeast")]
        public Northeast Northeast { get; set; }
 
        [JsonProperty("southwest")]
        public Southwest Southwest { get; set; }
    }
 
    public class Location
    {
 
        [JsonProperty("lat")]
        public double Lat { get; set; }
 
        [JsonProperty("lng")]
        public double Lng { get; set; }
    }
 
    public class Northeast2
    {
 
        [JsonProperty("lat")]
        public double Lat { get; set; }
 
        [JsonProperty("lng")]
        public double Lng { get; set; }
    }
 
    public class Southwest2
    {
 
        [JsonProperty("lat")]
        public double Lat { get; set; }
 
        [JsonProperty("lng")]
        public double Lng { get; set; }
    }
 
    public class Viewport
    {
 
        [JsonProperty("northeast")]
        public Northeast2 Northeast { get; set; }
 
        [JsonProperty("southwest")]
        public Southwest2 Southwest { get; set; }
    }
 
    public class Geometry
    {
 
        [JsonProperty("bounds")]
        public Bounds Bounds { get; set; }
 
        [JsonProperty("location")]
        public Location Location { get; set; }
 
        [JsonProperty("location_type")]
        public string LocationType { get; set; }
 
        [JsonProperty("viewport")]
        public Viewport Viewport { get; set; }
    }
 
    public class Result
    {
 
        [JsonProperty("address_components")]
        public AddressComponent[] AddressComponents { get; set; }
 
        [JsonProperty("formatted_address")]
        public string FormattedAddress { get; set; }
 
        [JsonProperty("geometry")]
        public Geometry Geometry { get; set; }
 
        [JsonProperty("partial_match")]
        public bool PartialMatch { get; set; }
 
        [JsonProperty("types")]
        public string[] Types { get; set; }
    }
 
    public class GoogleResponse
    {
 
        [JsonProperty("results")]
        public Result[] Results { get; set; }
 
        [JsonProperty("status")]
        public string Status { get; set; }
    }
 
}
 
Now when i try to parse it
GoogleResponse jsonData = JsonConvert.DeserializeObject<GoogleResponse>(result);
 
Then
 
Textbox1.text = jsonData.Results.AddressComponent.LongName.tostring();
 
Here after Results i'm not able to get AddressComponent.LongName getting error
 
Does not contain defination for AddressComponent.
 
As per as me now it should allow me to access but dont know why i'm not able to access it.
Posted 2-Mar-13 3:58am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100