开发者

Object to string and Vice Versa

I would like to convert the object to string and Vice Versa process. The situation is, we are using WCF Data开发者_如何转开发Service's WebGet method. This doesn't support object as return type. for this reason i need to convert the object to string in server side and string to object at client side. I doesn't want to add [Serializable] attribute, because the object i may convert is third party class and i can't serialize. what could be the best solution.


I think converting the third party class into some custom xml would be better. It might be very difficult to recreate the object from a string.

You can serialze a class to xml without using the [Serializable] attribute:

How to serialize an object to XML by using Visual C#


Since you have decided to convert the class to string, it would better be JSON string.

Check out this Json.Net library. which helps you to convert the strongly typed classe to json strings and vice versa.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜