序列号json
List list = new List(); foreach (DataRow dr in ds.Tables[0].Rows) { Part part = new Part(); part.PartID = Convert.ToInt32(dr["PartID"]); part.PartCode = dr["PartCode"].ToString(); list.Add(part); } DataContractJsonSerializer ser = new DataContractJsonSerializer(list.GetType()); string szJson = ""; //序列化 using (MemoryStream stream = new MemoryStream()) { ser.WriteObject(stream, list); szJson = Encoding.UTF8.GetString(stream.ToArray()); } return szJson;