How can I parse the elements of an array in a Json string using DataContractJsonSerializer? The syntax is:
{
"array":[
{
"elementsProperies":"SomeLiteral"
}
]
}
How can I parse the elements of an array in a Json string using DataContractJsonSerializer? The syntax is:
{
"array":[
{
"elementsProperies":"SomeLiteral"
}
]
}
I suggest using Json.net.
In it you would just call:
var jsonObj = JObject.Parse(yourjsonstring);
var elPropertyValue = (string)jsonObj.SelectToken("array[0].elementsProperies");
to get the "SomeLiteral"
.
You wouldn't necessarily "parse" a json string using DataContractJsonSerializer, but you can deserialize it into an object or list of objects using this. Here is a simple way to deserialize it to a list of objects if this is what you're after.
First you need to have an object type you plan on deserializing to:
You can then use something like the following method to deserialize your json string to a list of objects