开发者

C# serialization question

Is there any way to serialize/deserialize an object DataContractJsonSerializer as well as ISerializeable interface. as my requirement is I get开发者_开发知识库 JSon from a web service and deserialize it into a collections of objects say message. now I want to write all objects in the list to file.. is there any way please explain.


The DataContractJsonSerialiazer uses the DataContract / DataMember attributes, and doesn't care about ISerializable. Nothing prevents you from adding both the DataContract attribute and implemented the ISerializable interface, though.

You could also use the System.Web.Script.Serialization.JavaScriptSerializer class instead, I believe that it respects ISerializable. It isn't very fast though, and doesn't support dates, so I would really not recommend it.

Are you sure you cannot just use the DataContract serializer? You can use that with a binary writer if you want to: http://msdn.microsoft.com/en-us/library/ms752244.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜