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);
C# List转Json
最新推荐文章于 2024-01-11 17:25:15 发布