JSON字符串转JSON对象

<script type="text/javascript">
    var _notifyTRTemplate = "<tr><td><a href=‘./ZYYatHenan/Login_Return_XML.aspx?id={id}‘ target=‘_blank‘>{title}</a></td><td>{time}</td></tr>";
    $(function () {
        $.ajax({
            type: "GET",
            url: "ZYYatHenan/login.aspx",
            data: "num=5",
            success: function (msg) {
                var _data = eval("(" + msg + ")");
                var _appentHtml = "";
                //_data = (new Function("", "return " + msg))();
                for (var i = 0; i < _data.length; i++) {
                    _appentHtml += _notifyTRTemplate.replace("{id}", _data[i].ID).replace("{title}", _data[i].Title).replace("{time}", _data[i].PublishTime);
                }
                $("#notifyContent").append(_appentHtml);
            }
        });

    });
</script>
DataSet ds = DataAccessor.ExecuteDataSet(sql);
string returnJson = "";
JavaScriptSerializer jss = new JavaScriptSerializer();

if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
    StringBuilder sb = new StringBuilder();

    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        sb.Append("," + jss.Serialize(new NotifyItem(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(),
            dr[3].ToString(), dr[4].ToString(), dr[5].ToString())));
    }

    returnJson = "[" + sb.ToString().Substring(1) + "]";
}

Response.Write(returnJson);
Response.End();

    public class NotifyItem
    {
        public string publishTime = "";

        public string ID { get; set; }
        public string Title { get; set; }
        public string Type { get; set; }
        public string PublishTime { 
            get { return publishTime; } 
            set { publishTime = value.Trim(); } }
        public string PublishDept { get; set; }
        public string CreatePerson { get; set; }

        public NotifyItem(string id, string title, string type, string publisTime, 
            string publishDept, string createPerson)
        {
            ID = id;
            Title = title;
            Type = type;
            PublishTime = publisTime;
            PublishDept = publishDept;
            CreatePerson = createPerson;
        }
    };





郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。