I need to extract values from a JSON string so I can compare them. I only need to verify that they are in order (ascending/descending). I was going to check the first and second 'choices' and compare. I don't anything more advanced.
EDIT/UPDATE: How could I use wildcards (*) in this type of query to skip having each segment?
string one = (string)o[this.Context[*WILDCARD*]["cid1"]].ToString();
/* this works, but has too many []
string one = (string)o[this.Context["partner"]]
[this.Context["campaign"]]
[this.Context["segment1"]]
[this.Context["segment2"]]
[this.Context["qid2"]]
["community"]
[this.Context["cid1"]].ToString();
*/
{
"partner": {
"campaign": {
"round1": {
"round2": {
"def123": {
"community": {
"choicec": 28
},
"user": {
"choice": "choicec",
"writeDateUTC": "2015-06-15T17:21:59Z"
}
}
},
"abc321": {
"community": {
"choicec": 33
},
"user": {
"choice": "choicec",
"writeDateUTC": "2015-06-15T17:21:59Z"
}
}
}
}
}
}
using Newtonsoft.Jsonafter you've added the Nuget package):dynamic d = JsonSerializer.Deserialize(yourJsonString);then used.partner.campaign.round1.def123.community.choicecto access the choice number.dynamic? there must have been a concrete calss."cid1"property in your JSON. Just to confirm, you want to compare the values of the"choicec": 28and"choicec": 33properties to check if they're in order?