命名空间
using Newtonsoft.Json;
实例代码
/// <summary> /// 将list集合转换为json /// </summary> /// <param name="dtb">Dt</param> /// <returns>JSON字符串</returns> public static string List2Json(List<restaurant> list) { System.Collections.ArrayList dic = new System.Collections.ArrayList(); for (int i = 0; i < list.Count; i++) { System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>(); dic.Add(list[i]); } //序列化 return jss.Serialize(dic); }