netcore之json序列化
阿新 • • 發佈:2018-12-15
首先定義一個類
[DataContract] class RecordFile { [DataMember] public string StartTime { get; set; } [DataMember] public string EndTime { get; set; } [DataMember] public string Size { get; set; } }
序列化成字串
MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(RecordFileList)); ser.WriteObject(stream1, recordFileList); LogHelper.Info(Encoding.Default.GetString(stream1.ToArray()));