C# List转Json

来源:互联网 发布:网络视听许可证照租赁 编辑:程序博客网 时间:2024/05/22 12:27
 StringBuilder jsonstr = new StringBuilder("[");            for (int i = 0; i < list.Count; i++)            {                string message = RemoveHtmlTag(list[i].Message);                StringBuilder editorText = new StringBuilder(message);                string imgSrc = list[i].Thumbnail;                string id = list[i].Pid.ToString();                string date = Convert.ToDateTime(list[i].Postdatetime).ToString("yyyy年MM月dd日");                imgSrc = imgSrc.Replace(@"\", "/");                jsonstr.Append("{\"src\":\"").Append(imgSrc).Append("\",\"title\":\"").Append(list[i].Title).Append("\",\"time\":\"").Append(date).Append("\",\"id\":\"").Append(id).Append("\",\"message\":\"").Append(editorText.ToString()).Append("\"},");            }            string jsonStr = jsonstr.ToString();            jsonStr = jsonStr.Substring(0, jsonStr.LastIndexOf(','));            jsonStr += "]";            jsonstr = jsonstr.Replace(@"\", "/");            Console.Write(jsonstr);

原创粉丝点击