Here is my JSON:
{
"Name": "Eli",
"Age": 4,
"Children": {
"Moshe": {
"Age": 6,
"Characteristics": "Nice;Good;"
},
"Yossi": {
"Age": 3,
"Characteristics": "Hero;Brave"
}
}
}
Here is my JSON deserialization function:
public static object FromJSON<T>(string json)
{
using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(json)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
return serializer.ReadObject(stream);
}
}
I'm trying to serialize it to Person
object:
[DataContract]
public class Person
{
[DataMember]
public int Age;
[DataMember]
public string Name;
[DataMember]
public string Children;
}
As you can see, I do not want to get Children
into dictionary but to get it as is - JSON string.
Currently I'm doing it like this:
Person p = (Person)Extensions.FromJSON<Person>(output);
And I'm getting exception saying:
There was an error deserializing the object of type JSONSerialization.Person. End element 'item' from namespace 'item' expected. Found element 'a:item' from namespace 'item'.
Just to clarify: I do not want the children sub field to be parsed.