首页新闻找找看学习计划

请问这个json数据如何通过JavaScriptSerializer类反序列化成实体类?

0
悬赏园豆:100 [已解决问题] 解决于 2017-02-05 18:14

 

我想做一个天气预报功能

从气象台接口获取到了返回的json格式数据  并且生成了相应的实体类

但是反序列化之后weather对象属性值为null

请各位大神不吝赐教,小弟感激不尽!

 

实体类如下:

    public class Weatherinfo
    {
            /// <summary>
            /// 北京
            /// </summary>
            public string city { get; set; }
            /// <summary>
            /// 101010100
            /// </summary>
            public string cityid { get; set; }
            /// <summary>
            /// 18
            /// </summary>
            public string temp { get; set; }
            /// <summary>
            /// 东南风
            /// </summary>
            public string WD { get; set; }
            /// <summary>
            /// 1级
            /// </summary>
            public string WS { get; set; }
            /// <summary>
            /// 17%
            /// </summary>
            public string SD { get; set; }
            /// <summary>
            /// 1
            /// </summary>
            public string WSE { get; set; }
            /// <summary>
            /// 17:05
            /// </summary>
            public string time { get; set; }
            /// <summary>
            /// 1
            /// </summary>
            public string isRadar { get; set; }
            /// <summary>
            /// JC_RADAR_AZ9010_JB
            /// </summary>
            public string Radar { get; set; }
            /// <summary>
            /// 暂无实况
            /// </summary>
            public string njd { get; set; }
            /// <summary>
            /// 1011
            /// </summary>
            public string qy { get; set; }
            /// <summary>
            /// 0
            /// </summary>
            public string rain { get; set; }

    }


    public class Root
    {
        /// <summary>
        /// Weatherinfo
        /// </summary>
        public Weatherinfo weatherinfo { get; set; }
    }

----------------------------------------------------------------------------------------------

获取气象台json数据代码和反序列化代码如下:

问题补充:

气象局的json数据:

 

  {"weatherinfo":{"city":"北京","cityid":"101010100","temp":"18","WD":"东南风",
"WS":"1级","SD":"17%","WSE":"1","time":"17:05","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB",
"njd":"暂无实况","qy":"1011","rain":"0"}}

希望大神能帮我得到反序列化后的weather对象相应值

沿途放纵过往不究的主页 沿途放纵过往不究 | 初学一级 | 园豆:49
提问于:2017-02-04 10:28
< >
分享
最佳答案
0

public class Root

你要反序列化成Root

希望你以后别犯这种错误

收获园豆:100
吴瑞祥 | 高人七级 |园豆:28675 | 2017-02-04 11:04
其他回答(3)
0

给你答案,自己参考。

http://www.cnblogs.com/zhaozhan/archive/2011/01/09/1931340.html

异次元代码 | 园豆:101 (初学一级) | 2017-02-04 11:39
0

JsonConvert 类找一个调用一下。传入json字符串得到类型的找一个。

chengeng | 园豆:292 (菜鸟二级) | 2017-02-04 14:17
0

你要把返回的Json数据反序列化成Root这个类,完了后再取

大师兄丶 | 园豆:836 (小虾三级) | 2017-02-05 15:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册