I get the InvalidOperationException when I try to deserialize a json string for my person object. It states that my Person object is not supported for deserialization
[DataContract]
public class Person
{
public string FirstName {get;set;}
public string LastName {get; set;}
public int Id {get; set;}
}
An example of the json string
[{"name":"FirstName","value":"John"},{"name":"LastName","value":"Doe"},{"name":"Id","value":"1001"}]
And here’s where I get my exception
Person p = new JavaScriptSerializer().Deserialize<Person>(json);
I’ve tried the DataContractJsonSerializer too without much luck.
I have tested your code and found the problem.
Your jSon string provided a array of
Person. Change toPerson[]and it will work.Here is my test code
Update
Your jSon string is not in the right format. The Deserializer cant find the property to assign your values.
The right would be.
This is a right format
Test Code