我想做一个天气预报功能
从气象台接口获取到了返回的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对象相应值
public class Root
你要反序列化成Root
希望你以后别犯这种错误
给你答案,自己参考。
http://www.cnblogs.com/zhaozhan/archive/2011/01/09/1931340.html
JsonConvert 类找一个调用一下。传入json字符串得到类型的找一个。
你要把返回的Json数据反序列化成Root这个类,完了后再取