tags:

views:

300

answers:

2

To start, I know there are two "kinds" of JSON serialization currently built into ASP.Net: you can either use the JavaScriptSerializer class to serialize your object to JSON or the new DataContractJsonSerializer class to convert a object to JSON.

If you use the JavaScriptSerializer() method, you must mark your class as Serializable() -- if you use the DataContractJsonSerializer method, you must mark your class as DataContract(), and mark your properties as DataMembers().

If you want, you can specify a NAME attribute for each DataMembers, so when the property gets serialized/deserialized, it uses that name. For my purposes, I see this as being useful to make the JSON not so "wordy". For example, instead of stating "UserID" as my property (and having it repeat throughout my JSON object), I'd like to simply use "u". Less data across the wire, etc.

The two serialization engines render a bit different, and you can only use the JavaScriptSerializer with ASP.Net Web/Script Methods. Therein lies my problem.

Is there a equivalent way of setting a property name to something else, strictly for the purposes of serialization/deserialization using the regular JavaScriptSerializer?

A: 

No, there isn't.

Robert C. Barth
A: 

Assuming UTF-8 you are saving 40 bits over the wire by this technique, its not worth the sleep lost.

FlySwat

related questions