麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

csharp:using Newtonsoft.Json.Net2.0 in .net 2.0 webform

2019-11-17 01:34:16
字體:
來源:轉載
供稿:網友

csharp:using Newtonsoft.Json.Net2.0 in .net 2.0 webform

 /// <summary>    /// http://www.weather.com.cn/data/sk/101280601.html    ///  {"weatherinfo":{"city":"深圳","cityid":"101280601","temp":"32","WD":"西南風","WS":"4級","SD":"68%","WSE":"4","time":"16:40","isRadar":"1","Radar":"JC_RADAR_AZ9755_JB"}}    /// 20140531 涂聚文 Geovin Du    /// </summary>    public class WeatherInfo     {        //public  string city;        //public string cityid;        //public string temp;        //public string WD;        //public string WS;        //public string SD;        //public string WSE;        //public string time;        //public string isRadar;        //public string Radar;        string _city;        string _cityid;        string _temp;        string _WD;        string _WS;        string _SD;        string _WSE;        string _time;        string _isRadar;        string _Radar;        /// <summary>        /// 城市名稱        /// </summary>        public string city        {            get            {                return _city;            }            set            {                _city = value;            }        }        /// <summary>        /// 城市代碼        /// </summary>        public string cityid        {            get            {                return _cityid;            }            set            {                _cityid = value;            }            //get;            //set;        }        /// <summary>        /// 溫度        /// </summary>        public string temp        {            get            {                return _temp;            }            set            {                _temp = value;            }        }        /// <summary>        /// 風向        /// </summary>        public string WD        {            get            {                return _WD;            }            set            {                _WD = value;            }              }        /// <summary>        /// 風級        /// </summary>        public string WS        {            get            {                return _WS;            }            set            {                _WS = value;            }              }        /// <summary>        /// 濕度        /// </summary>        public string SD        {            get            {                return _SD;            }            set            {                _SD = value;            }             }        /// <summary>        ///         /// </summary>        public string WSE        {            get            {                return _WSE;            }            set            {                _WSE = value;            }        }        /// <summary>        /// 發布時間        /// </summary>        public string time        {            get            {                return _time;            }            set            {                _time = value;            }        }        /// <summary>        ///         /// </summary>        public string isRadar        {            get            {                return _isRadar;            }            set            {                _isRadar = value;            }              }        /// <summary>        ///         /// </summary>        public string Radar        {            get            {                return _Radar;            }            set            {                _Radar = value;            }                }        PRivate Dictionary<string, object> _theRest = new Dictionary<string, object>();        public Dictionary<string, object> TheRest        {            get { return _theRest; }        }           // public Dictionary<string, decimal> Rates { get; set; }    }
/// <summary>    /// http://www.weather.com.cn/data/sk/101280601.html    /// 20140531 涂聚文 Geovin Du    /// </summary>    public class WeatherInfoConverter : CustomCreationConverter<WeatherInfo>    {        public override WeatherInfo Create(Type objectType)        {            return new WeatherInfo();        }        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)        {            WeatherInfo mappedObj = new WeatherInfo();            //get an array of the object's props so I can check if the JSON prop s/b mapped to it            PropertyInfo[] myPropertyInfo;            myPropertyInfo = objectType.GetProperties();            string objProps = string.Empty;            //for (int i = 0; i < myPropertyInfo.Length; i++)            //{            //    objProps = objProps +" "+ myPropertyInfo[i].ToString();            //}            foreach (PropertyInfo pi in objectType.GetProperties())            {                object value1 = pi.GetValue(mappedObj, null);//用pi.GetValue獲得值                  objProps = objProps + " " + pi.Name;//獲得屬性的名字,后面就可以根據名字判斷來進行些自己想要的操作                  //獲得屬性的類型,進行判斷然后進行以后的操作,例如判斷獲得的屬性是整數                  //if(value1.GetType() == typeof(int))                   //{                   //    //進行你想要的操作                  //}               }               //objProps = myPropertyInfo[0].Name.ToLower().ToString(); //objectType.GetProperties().Select(p => p.Name.ToLower()).ToArray();            //loop through my JSON string            while (reader.Read())            {                //if I'm at a property...                if (reader.TokenType == JsonToken.PropertyName)                {                    //convert the property to lower case                    string readerValue = reader.Value.ToString().ToLower();                    if (reader.Read())  //read in the prop value                    {                        //is this a mapped prop?                        if (objProps.Contains(readerValue))                        {                            //get the property info and set the Mapped object's property value                            PropertyInfo pi = mappedObj.GetType().GetProperty(readerValue, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);                            object convertedValue = Convert.ChangeType(reader.Value, pi.PropertyType);                            pi.SetValue(mappedObj, convertedValue, null);                        }                        else                        {                            //otherwise, stuff it into the Dictionary                            mappedObj.TheRest.Add(readerValue, reader.Value);                        }                    }                }            }            return mappedObj;        }    }

  /// <summary>    /// http://www.weather.com.cn/data/sk/101280601.html    /// http://www.weather.com.cn/data/cityinfo/101280601.html    /// http://geoip.weather.com.cn/g/    /// http://m.weather.com.cn/data/101190101.html    /// 20140531 涂聚文 Geovin Du    /// {"weatherinfo":{"city":"深圳","cityid":"101280601","temp":"32","WD":"西南風","WS":"4級","SD":"68%","WSE":"4","time":"16:40","isRadar":"1","Radar":"JC_RADAR_AZ9755_JB"}}    /// </summary>    public partial class WebForm1 : System.Web.UI.Page    {        string json_data = string.Empty;        string url = string.Empty;        //WeatherInfo we = new WeatherInfo();        /// <summary>        /// http://social.msdn.microsoft.com/Forums/en-US/4392c97a-3c6e-45b9-99c9-12a979c64910/c-20-jsonnet        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        protected void Page_Load(object sender, EventArgs e)        {            try            {                url = "http://www.weather.com.cn/data/sk/101280601.html";                WebClient wc = new WebClient();                wc.Encoding = System.Text.Encoding.UTF8;//定義對象語言                json_data = wc.DownloadString(url);                //JsonConvert.DeserializeObject<Table>(json_data);                //var ser = new javaScriptSerializer();                //we = _download_serialized_json_
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产免费激情视频 | 91av久久 | 久久久精品视频网站 | 成人一区二区三区四区 | 久久精品影视 | 欧美成人精品一区 | 国产 一区 精品 | 欧美成人激情在线 | v11av在线视频成人 | fc2国产成人免费视频 | av电影手机在线看 | www中文在线 | 久久亚洲一区二区三区成人国产 | 欧美性生活久久久 | 91 在线免费观看 | 精品国产乱码久久久久久丨区2区 | 一区二区久久精品66国产精品 | 国产日韩在线 | 在线成人免费观看 | 日本成人高清视频 | 一级做a爰片性色毛片2021 | lutube成人福利在线观看 | 中文字幕欧美专区 | 欧美综合在线观看视频 | 国产精品91久久久 | 一级大黄毛片 | 色交视频 | 一本精品999爽爽久久久 | 欧美成人精品一区 | 午夜爽爽爽男女免费观看hd | 毛片视频大全 | 夏目友人帐第七季第一集 | 成人性生活视频在线观看 | 在线成人一区 | 91短视频版高清在线观看www | 久久逼逼| 欧美a视频在线观看 | 亚洲一级成人 | 色综合久久久久久久久久久 | 国产羞羞视频 | 调教小男生抽打尿孔嗯啊视频 |