开发者

Silverlight json won't serialize

开发者 https://www.devze.com 2023-03-07 16:43 出处:网络
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.

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();

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 object开发者_如何学Cs (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?


The stream cursor is pointing to the end (after everything was written). Add the line "ms.Position = 0;" before creating the StreamReader.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号