Silverlight JSON不会序列化 [英] Silverlight json won't serialize
问题描述
我一直在尝试在Silverlight中序列化一些json数据.我正在使用以下代码
I have been trying to serialize some json data in Silverlight. I am using the following code
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(stacks.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, stacks);
StreamReader reader = new StreamReader(ms);
string json = reader.ReadToEnd();
尝试序列化.这没用.这是我发现的唯一一个不会在Visual Studio中产生错误的示例.我正在传递自定义编码对象(堆栈)的列表.当我尝试查看结果时,我得到一个空白字符串.有人对如何指出正确的方向有一些想法吗?
to attempt the serialization. It does not work. It was the only example I could find that did not produce errors in Visual Studio. I am passing a list of custom coded objects (stacks). When I try to view the results I am getting a blank string. Anyone got some ideas on how to point me in the right direction?
推荐答案
流游标指向末尾(写完所有内容之后).添加行"ms.Position = 0;"在创建StreamReader之前.
The stream cursor is pointing to the end (after everything was written). Add the line "ms.Position = 0;" before creating the StreamReader.
这篇关于Silverlight JSON不会序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!