C# 将对象序列化为Json格式

public static string JsonSerializer<T>(T t)

{

    DataContractJsonSerializer ser = new  DataContractJsonSerializer(typeof(T));

    MemoryStream ms = new MemoryStream();

    ser.WriteObject(ms, t);

    string jsonString = Encoding.UTF8.GetString(ms.ToArray());

    ms.Close();

    return jsonString;

}

 

你可能感兴趣的:(json)