Code Bye

JSON字符串转对象

            
string s = "{"content":{"features":"cpAutoSentence:false","timeout":"2016-05-2319:00:00","count":"4","gmtCreate":"2016-05-2319:00:00","taskStatus":"4","taskName":"商家处理工单","taskId":"43525","workOrderId":"10016052502373003"}}";
JavaScriptSerializer js = new JavaScriptSerializer();
content sn = js.Deserialize<content>(s);
Response.Write(sn.taskName);//注意这行,打出来是空白的,没有值,本来应该显示“商家处理工单”
public class content
{
    public string features { get; set; }
    public string timeout { get; set; }
    public string count { get; set; }
    public string gmtCreate { get; set; }
    public string taskStatus { get; set; }
    public string taskName { get; set; }
    public string taskId { get; set; }
    public string workOrderId { get; set; }
}

问一下,上面这样的转换为什么不行?taskName是有值的,但是打出来是空白的

解决方案

100

public class container
        {
            public content content { get; set; }
        }
            string s = "{"content":{"features":"cpAutoSentence:false","timeout":"2016-05-2319:00:00","count":"4","gmtCreate":"2016-05-2319:00:00","taskStatus":"4","taskName":"商家处理工单","taskId":"43525","workOrderId":"10016052502373003"}}";
            JavaScriptSerializer js = new JavaScriptSerializer();
            var sn = js.Deserialize<container>(s);
            Console.Write(sn.content.taskName);//注意这行,打出来是空白的,没有值,本来应该显示“商家处理工单”

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明JSON字符串转对象