I'm building a Silverlight wp7 app in C#. I have objects that I want to convert to and from JSON. I'm using JSON.NET.
Several properties of these objects require a bit of logic to initialize. Is there some way to use a custom converter method? (One such property is a List of strings. The data is given as a single String, and in the constructor the class splits it into a list.)
Also, I'd rather have the properties be read only, but they have to be read-write for conversation (right?). That's kind of a pain.
Or am I stuck doing the conversion manually?
Writing a JsonConverter allows you to manually serialize/deserialize a type. You could write one for a List that will split the string when reading and concatenate it when writing JSON.
If you are calling for the objects through a web service, you can change the encoding of the web service response to return JSON.
http://blog.davebouwman.com/posting-data-to-aspnet-json-services-with-doj
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.