C# List集合转Json字符串示例代码
将list集合转换为Json字符串简单实现代码:
public static string GetJosn(List<CalendarInfo> list) { string jsonStr = "["; if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { var entity = list[i]; if (i > 0) { jsonStr += ","; } //str += "['" + entity.Id + "','" + entity.Title.Replace("\\", @"\\").Replace("'", @"\'") + "',new Date(" + TimeHelper.MilliTimeStamp(entity.StartTime) + "),new Date(" + TimeHelper.MilliTimeStamp(entity.EndTime) + ")," + (entity.IsAllDayEvent ? "1" : "0") + "," + TimeHelper.CheckIsCrossEvent(entity) + "," + (2 == 2 ? "1" : "0") + "," + (string.IsNullOrEmpty(entity.Category) ? "-1" : entity.Category) + "]"; jsonStr += "['" + entity.Id + "','" + entity.Subject.Replace("\\", @"\\").Replace("'", @"\'") + "',new Date(" + TimeHelper.MilliTimeStamp(entity.StartTime) + "),new Date(" + TimeHelper.MilliTimeStamp(entity.EndTime) + ")," + (entity.IsAllDayEvent ? "1" : "0") + "," + TimeHelper.CheckIsCrossEvent(entity) + "," + (1 == 2 ? "1" : "0") + "," + (string.IsNullOrEmpty(entity.Category) ? "-1" : entity.Category) + ",1,'" + "本公司" + "','" + "" + "" + (string.IsNullOrEmpty("") ? "" : ",") + "" + "' ]"; } } jsonStr += "]"; return jsonStr; }