using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
public class JsonTools
{
/// <summary>
/// 从一个对象信息生成Json串
/// </summary>
/// <param name="obj">The object.</param>
/// <returns>JSON</returns>
public static string ObjectToJson(object obj)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
MemoryStream stream = new MemoryStream();
serializer.WriteObject(stream, obj);
byte[] dataBytes = new byte[stream.Length];
stream.Position = 0;
stream.Read(dataBytes, 0, (int)stream.Length);
return Encoding.UTF8.GetString(dataBytes);
}
/// <
JSON转化源码(.NET3.0以上)
最新推荐文章于 2022-05-24 05:21:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)