// http://www.juso.go.kr/addrlink/addrLinkApi.do?currentPage=1&countPerPage=10&keyword=%EA%B3%A0%EB%A7%88%EB%A1%9C88&confmKey=U01TX0FVVEgyMDE5MDEyOTEwMDQ0NjEwODQ4MzI= private static async Task <JusoResult> GetJibunJuso(string address) { string page = "http://www.juso.go.kr/addrlink/addrLinkApi.do?" + "currentPage=1&countPerPage=10&keyword=" + address + "&confmKey=" + jusoApiKey + "&resultType=json"; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (HttpResponseMessage response = await client.GetAsync(page)) using (HttpContent content = response.Content) { // return await content.ReadAsAsync<ForecastGribResult>(); // https://www.newtonsoft.com/json var stringResult = await content.ReadAsStringAsync(); JusoResult result = JsonConvert.DeserializeObject <JusoResult>(stringResult); return(result); } } }
/* * http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getTMStdrCrdnt? * umdName=일도이동 * &pageNo=1 * &numOfRows=10 * &ServiceKey=73Jjl5lZRvBRKkGsPnGmZ7EL9JtwsWNi3hhCIN8cpVJzMdRRgyzntwz2lHmTKeR1tp7NWzoihNGGazcDEFgh8w%3D%3D * &_returnType=json * */ private static async Task <AirDataResult> GetAirData(string url, string umd) { JusoResult jibunJuso = await GetJibunJuso(umd); string page = url + "umdName=" + UtilManager.GetUmdFromAddress(jibunJuso.results.juso[0].jibunAddr) + "&pageNo=1" + "&numOfRows=10" + "&ServiceKey=" + ServiceKeyForAir + "&_returnType=json"; Console.WriteLine("GetAirData says: {0}", page); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); using (HttpResponseMessage response = await client.GetAsync(page)) using (HttpContent content = response.Content) { // TmX, TmY 조회 var stringResult = await content.ReadAsStringAsync(); AirDataMetaResult resultTmXY = JsonConvert.DeserializeObject <AirDataMetaResult>(stringResult); // 측정소명 조회 AirDataMetaResult resultStationName = await GetStationName("http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getNearbyMsrstnList?", resultTmXY.list[0].tmX, resultTmXY.list[0].tmY); // 측정값 조회 AirDataResult result = await GetAirMeasure("http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?", resultStationName.list[0].stationName); return(result); } } }