Error converting JSON to .Net object in

Vinay Kumar Chella提出了一个问题:Error converting JSON to .Net object in,或许与您遇到的问题类似。


Instead of doing this manually I would recommend using the built in lightweight JavaScriptSerializer. No attributes are required on the classes you want to serialize/deserialize.

It's also more flexible and faster than the DataContractJsonSerializer, since it does not have to care about all the wcf stuff. Additionally it has generic overloads that make it very simple to use AND it can also handle anonymous types.


var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var objectAsJsonString = serializer.Serialize(objectToSerialize);


var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
JsonFeaturedOffer deserializedObject = serializer.Deserialize<JsonFeaturedOffer>(s_JsonBaseDate);

To make it even easier you can create Extension methods that will give you json serialization/deserialization directly on the objects/strings.