This project has moved and is read-only. For the latest updates, please go here.

Deserialize json array to Object array

Jul 3, 2009 at 1:43 PM


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

"Property":"Usage type",
,"Property":"Supply type",
"Description":"L - Supply from the Grid",
"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.