Deserialize json array to Object array

Jul 3, 2009 at 1:43 PM

Hi,

I am a real n00b in this area. All I know is that I receive data in this format (2 elements in an array):

[
{"rn":"1",
"Property":"Usage type",
"Value":"GV",
"PropertyValueId":"1000002309",
"PropertyId":"95",
"Description":"GV",
"IsRestricted":"true",
"IsRequired":"true",
"IsReadOnly":"false",
"ValueDescription":"GV"},
{"rn":"2"
,"Property":"Supply type",
"Value":"L",
"PropertyValueId":"1000002310",
"PropertyId":"103",
"Description":"L - Supply from the Grid",
"IsRestricted":"true",
"IsRequired":"true",
"IsReadOnly":"false",
"ValueDescription":"L - Supply from the Grid"
}
]

Now I created an internal class to map the elements:

       internal class PropertyGridRow
        {
            string rn { get; set; }
            string Property { get; set; }
            string Value { get; set; }
            string PropertyValueId { get; set; }
            string PropertyId {get;set;}
            string Description { get; set; }
            string IsRestricted { get; set; }
            string IsRequired { get; set; }
            string IsReadOnly { get; set; }
            string ValuedDescription { get; set; }
        }

When trying to deserialize with this statement:

PropertyGridRow[] oa = (PropertyGridRow[])JsonConvert.DeserializeObject(jsonString, typeof(PropertyGridRow[]));

I do get a PropertyGridRow array with 2 elements, but all properties are null.

What am I doing wrong?

Jul 3, 2009 at 1:44 PM

typo corrected string ValueDescription { get; set; }

did not change the output though ;)

Jul 3, 2009 at 2:29 PM

Never mind guys ^&*^@*(&^!@&^!

I forgot to make the properties public ;'(

Jul 17, 2009 at 2:30 AM

Try this:

List<PropertyGridRow> rows = JsonConvert.DeserializeObject<List<PropertyGridRow>>(jsonString);

Mar 18, 2010 at 9:53 PM

Thank you elishnevsky.