using DataServer.api; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Web.Http; namespace DongYingAPI.Controllers.api { public class GetMeteorologicalStationController : ApiController { public HttpResponseMessage Get() { var res = new get_meteorological_station(); try { var data = new List(); var model1=new meteorological_stationData(); model1.WeatherName = "室外噪音"; model1.WeatherValue = "中"; data.Add(model1); var model2 = new meteorological_stationData(); model2.WeatherName = "温度"; model2.WeatherValue = "2"; data.Add(model2); var model3 = new meteorological_stationData(); model3.WeatherName = "风力"; model3.WeatherValue = "风力2级"; data.Add(model3); var model4 = new meteorological_stationData(); model4.WeatherName = "湿度"; model4.WeatherValue = "32"; data.Add(model4); var model5 = new meteorological_stationData(); model2.WeatherName = "紫外线强度"; model2.WeatherValue = "中等"; data.Add(model2); var model6 = new meteorological_stationData(); model3.WeatherName = "空气质量"; model3.WeatherValue = "中"; data.Add(model3); res.code = 200; res.msg = "成功"; res.data = data; } catch (Exception ex) { res.code = 500; res.msg = "失败," + ex.Message; } HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(res), Encoding.GetEncoding("UTF-8"), "application/json") }; return result; } } }