I am trying to Deserialize a JSON response from Google Maps Geocode.
Those are the classes I coded based on the response.
public class GoogleGeoCodeResponse
{
public string status { get; set; }
public results[] results { get; set; }
}
public class results
{
public address_component[] address_components { get; set; }
public String formatted_address { get; set; }
public Geometry geometry { get; set; }
public Boolean partial_match { get; set; }
public string[] types { get; set; }
}
public class address_component
{
public String long_name { get; set; }
public String short_name { get; set; }
public String[] types { get; set; }
}
public class Geometry
{
public bounds_viewport bounds { get; set; }
public LatLong location { get; set; }
public String location_type { get; set; }
}
public class bounds_viewport
{
public LatLong northeast { get; set; }
public LatLong southwest { get; set; }
}
public class LatLong
{
public double lon { get; set; }
public double lat { get; set; }
}
On my form button click I use this code.
var json = new WebClient().DownloadString("url");
GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(json);
MessageBox.Show(test.results[0].geometry.location.lat + " / " + test.results[0].geometry.location.lon);
Then I wanted to see if I get the correct information but I’m getting:
“Error 1 Inconsistent accessibility: property type ‘WindowsFormsApplication1.results[]’ is less accessible than property ‘WindowsFormsApplication1.GoogleGeoCodeResponse.results'”
I’ve looked a bunch of post with the same problem but they always had something private or internal somewhere that would lead to this error. As you can see everything I declared is public.
I don’t understand why something public inside of a class would be more accessible than the class itself.
I am fairly new to C# and JSON so this might be something really simple.
Ok so I took all of my class and put the code out of my form’s class and it worked. I put it back in the class and it still worked I don’t know what I have changed, maybe it was just bugged or something anyway thanks for the help!