public async Task <IHttpActionResult> GetBusStop(string cityEN, string routeName) { //Initial IHttpActionResult responseResult; IBusStop repos = DataFactory.BusStopRepository(); //Get Json String HttpClient client = new HttpClient(); //Setting target Url string targetURI = ConfigurationManager.AppSettings["BusStopURL"].ToString() + "/" + cityEN + "/" + routeName + "?$format=JSON"; string response = await client.GetStringAsync(targetURI); //Deserialize var busStopSource = JsonConvert.DeserializeObject <IEnumerable <BusStopDeserialize> >(response); //將需要的欄位取出後序列化 var jsonSerialize = JsonConvert.SerializeObject(repos.GetBusStop(busStopSource)); //做成JSON字串包裝到最後輸出 StringContent responseMsgString = new StringContent(jsonSerialize, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage responseMsg = new HttpResponseMessage() { Content = responseMsgString }; responseResult = ResponseMessage(responseMsg); return(responseResult); }
/// <summary> /// 取得公車站牌資訊 /// </summary> /// <param name="routeName">路線名稱</param> /// <returns></returns> public async Task <ActionResult> GetBusStopInfo(string cityEN, string routeName) { IBusStop repos = DataFactory.BusStopRepository(); //Get Json String HttpClient client = new HttpClient(); //Setting target Url string targetURI = ConfigurationManager.AppSettings["BusStopURL"].ToString() + "/" + cityEN + "/" + routeName + "?$format=JSON"; string response = await client.GetStringAsync(targetURI); //Deserialize var busStopSource = JsonConvert.DeserializeObject <IEnumerable <BusStopDeserialize> >(response); return(Content(JsonConvert.SerializeObject(repos.GetBusStop(busStopSource)), "application/json")); }