Silverlight JSON不会序列化 [英] Silverlight json won't serialize

查看:98
本文介绍了Silverlight JSON不会序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆