tags:

views:

188

answers:

2

I am trying to deserialize some JSON that I am grabbing from an asmx service into a list of objects. All of the fields in the class match fields in the JSON, the JSON is coming back valid, but I get the seemingly cryptic error: Value cannot be null. Parameter name: type. There is no parameter named type in any of my objects. Has anyone seen this before? Here is the code that is throwing the error. System.Web.Script.Serialization.JavaScriptSerializer serr = new System.Web.Script.Serialization.JavaScriptSerializer();

    List<Rejection> l = serr.Deserialize<List<Rejection>>(json);

json is a string declared earlier and coming back with valid json that matches the field in my class. Does the class you are deserializing to's name have to match what is in the __type attribute in the json?

A: 

I'm not sure exactly where is your problem, but try following code:


string input = "..."; // your asmx data
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<YourCustomClass> novos = new List<YourCustomClass>(
    serializer.Deserialize<YourCustomClass[]>(input)));
Rubens Farias
A: 

I solved my problem by avoiding the javascript serializer all together and using the json.net library. Worked like a charm.

Chris Westbrook

related questions