views:

206

answers:

0

I have a RESTFUL WCF service returning a .NET custom type as json string. I am using .NET 3.5 framework and I am using JavaScriptSerializer for deserializing it in to my custom type. Serialization to json is handled by WCF.

using (WebResponse resp = req.GetResponse())
            {
                using (System.IO.StreamReader sreader = new System.IO.StreamReader(resp.GetResponseStream()))
                {
                    string jsonString = sreader.ReadToEnd();
                    CustomType myType = new CustomType();
                    System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    myType = serializer.Deserialize<CustomType>(jsonString);
                    return myType;
                }
            }

The problem is that, I have a property (or element) of the CustomType which is generic list of another custom type ChildObject. They are in different namespaces. When I deserialize using the code above, I get all the properties of the CustomType myType including a list of ChildObject. But all the properties of the ChildObject is null. The string returned from the stream reader has all the values for the ChildObject. the values are lost when deserializing. Can anyone help me with this please?

Here is the json string

{\"CustomTypeName":myType1,
  \"ChildObject\":[
    {\"id\":\"ddvadb2d-d126-4e29-ab23-564adc46413c\",
     \"level\":1,\"enabledGrid\":true,\"Order\":0,
     \"xtPropertyType\":\"LocationAddress\",\"address1\":\"whatever street\",
      \"address2 \":\"P.O Box 27\",\"city\":\"Foster\",
      \"country\":\"United States\",\"state\":\"Portland\",\"zip\":\"70149\"}, 
    {\"id\":\"devadb2d-d126-4e29-ab23-564adc46413c\",
     \"level\":1,\"enabledGrid\":true,\"Order\":0,
     \"xtPropertyType\":\"LocationAddress\",\"address1\":\"whatever street\",
      \"address2 \":\"P.O Box 27\",\"city\":\"Foster\",
      \"country\":\"United States\",\"state\":\"Portland\",\"zip\":\"70149\"} 
     ],
  \"ErrorMessage\":null}