// GET: AlertCust public async Task <ActionResult> Index() { //Initialize IAlert repos = DataFactory.AlertRepository(); //Setting target Url string targetURI = ConfigurationManager.AppSettings["AlertInfoURL"].ToString(); HttpClient client = new HttpClient(); client.MaxResponseContentBufferSize = Int32.MaxValue; //Get Parking Json Format (not completed json) var response = await client.GetStringAsync(targetURI); JObject o = (JObject)JsonConvert.DeserializeObject(response); StringBuilder sb = new StringBuilder(o.SelectToken("entry").ToString()); string alertString = sb.Replace("#", string.Empty).Replace("@", string.Empty).ToString(); //Deserialize var collection = JsonConvert.DeserializeObject <IEnumerable <AlertDeserialize> >(alertString); //Add Alert Info repos.AddAlertInfo(collection); return(View()); }
/// <summary> /// 取得災害警示資訊 /// </summary> /// <returns></returns> public ActionResult GetAlertInfo(string keyWord) { //Initial Variables IAlert repos = DataFactory.AlertRepository(); return(Content(JsonConvert.SerializeObject(repos.getAlertInfo(keyWord)), "application/json")); }
/// <summary> /// 取得災害警示資訊(全台) /// </summary> /// <param name="keyWord">鄉鎮區(如:桃園)</param> /// <returns></returns> public List <AlertInfo> GetAlertInfo(string keyWord) { //Initial Variables IAlert repos = DataFactory.AlertRepository(); return(repos.getAlertInfo(keyWord)); }
//[SwaggerImplementationNotes("取得所有公車路線")] public IHttpActionResult GetAlertInfo(string keyWord) { //Initial IHttpActionResult responseResult; IAlert repos = DataFactory.AlertRepository(); //序列化撈出來的資料 var jsonSerialize = JsonConvert.SerializeObject(repos.getAlertInfo(keyWord)); //做成JSON字串包裝到最後輸出 StringContent responseMsgString = new StringContent(jsonSerialize, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage responseMsg = new HttpResponseMessage() { Content = responseMsgString }; responseResult = ResponseMessage(responseMsg); return(responseResult); }