지오 코딩을 위해 Google지도 api에서 json을 구문 분석하려고합니다.C# JSON 응답에서 HttpClient를 사용하여 특정 객체 가져 오기
json으로는 다음과 같습니다
{
"results" : [
{
"address_components" : [
{
"long_name" : "1600",
"short_name" : "1600",
"types" : [ "street_number" ]
},
{
"long_name" : "Amphitheatre Parkway",
"short_name" : "Amphitheatre Pkwy",
"types" : [ "route" ]
},
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "94043",
"short_name" : "94043",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224277,
"lng" : -122.0843288
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4237766802915,
"lng" : -122.0829798197085
},
"southwest" : {
"lat" : 37.4210787197085,
"lng" : -122.0856777802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
내가 위도와 경도로 location
객체에만 관심과 HttpContent로 그들을 검색하는 C#을 내 JSON 개체 트리를 탐색하는 방법을 알고 싶습니다 HttpClient에서 GetAsync의 응답. 다음 코드 단편은 내 요청이 어떻게 이루어지는 지 보여줍니다.
public async Task<Coordinates> GeoCode(string address)
{
HttpClient client= new HttpClient();
var baseUrl = "http://maps.google.com/maps/api/geocode/json?address=";
var addressEncoded = WebUtility.UrlEncode(address);
var response= await client.GetAsync(baseUrl + addressEncoded);
if(response.IsSuccessStatusCode)
{
//read location ...
}
}
어떻게 위치 개체를 읽을 수 있습니까?
정말 고마워요! – NicolasL