I have the following json data, I need to read the data from it and them perform some comparisons.
{"expiration": "2013-04-01T00:00:00Z",
"conditions": [
{"bucket": "the-s3-bucket-in-question"},
["starts-with", "$key", "donny/uploads/"],
{"acl": "private"},
["eq", "$Content-Type", "text/plain"],
["starts-with", "x-amz-meta-yourelement", ""],
["content-length-range", 0, 1048576]
]
}
By using the following code I have found the first element
var policy = Encoding.UTF8.GetString(policyByteArray);
JObject obj = JObject.Parse(policy);
string policyexpiration = obj.First.First.Path;
I have used JToken
for finding all the conditions but I am getting only one element in that array. Can you please help me to get all the elements present in the conditions.
Following is the way I have used JToken
JToken entireJson = JToken.Parse(policy);
var items = entireJson["conditions"].Value<JArray>()[0];
XmlDocument xdoc = (XmlDocument)JsonConvert.DeserializeXmlNode(items.ToString(), "root");
XmlNode xmlarray = xdoc.GetElementsByTagName("root")[0];
foreach (XmlNode xmlelement in xmlarray)
{
}