-1

如何使用 c# 在 Windows 8 中将 memorystream 对象编码为字符串?

代码片段:

  DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
        using (MemoryStream ms = new MemoryStream())
        {
            serializer.WriteObject(ms, obj);

            //return Encoding.Default.GetString(ms.ToArray()); //problem in this line
        }
4

2 回答 2

0
ms.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(ms); // or whatever encoding
return reader.ReadToEnd();
于 2013-10-22T13:40:52.277 回答
0

阅读Unicode 和 .NET并使用

Encoding.UTF8.GetString(ms.ToArray());
于 2013-10-22T13:38:51.483 回答