GoogleMapsGeocodeからJSON応答を逆シリアル化しようとしています。
これらは、応答に基づいてコーディングしたクラスです。
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; }
}
フォームボタンをクリックして、このコードを使用します。
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);
次に、正しい情報が得られるかどうかを確認したかったのですが、次のようになりました。
「エラー1アクセシビリティの一貫性がありません:プロパティタイプ'WindowsFormsApplication1.results[]'はプロパティ'WindowsFormsApplication1.GoogleGeoCodeResponse.results'よりもアクセスしにくいです。」
私は同じ問題を抱えたたくさんの投稿を見てきましたが、彼らは常にこのエラーにつながるプライベートまたは内部の何かを持っていました。ご覧のとおり、私が宣言したものはすべて公開されています。
クラス内のパブリックなものがクラス自体よりもアクセスしやすい理由がわかりません。
私はC#とJSONにかなり慣れていないので、これは本当に単純なことかもしれません。