Here, Below is my JSON.
//MyJSON
{
"Apply": "Access",
"JSON": [{
"id": 1,
"File": "File 1",
"Value": 0
},
{
"id": 2,
"File": "File 2",
"Value": 0
},
{
"id": 3,
"File": "File 3",
"Value": 1
},
{
"id": 4,
"File": "File 4",
"Value": 1
}]
}
//JSON 1
{
"Apply": "Access",
"JSON": [{
"id": 1,
"File": "File 1",
"Value": 0
},
{
"id": 2,
"File": "File 2",
"Value": 0
}]
}
//JSON 2
{
"Apply": "Access",
"JSON": [{
"id": 3,
"File": "File 3",
"Value": 1
},
{
"id": 4,
"File": "File 4",
"Value": 1
}]
}
For making the above response I'm trying to using the below code.
var Response = JObject.Parse(MyJSON);
JArray JResponse = JArray.Parse(Response["JSON"].ToString());
foreach (var item in JResponse)
{
//Here I tried to compare the JArray With the String
try
{
Console.WriteLine(item["Value"]);
//if (item["Value"].Equals(0))
if (item["Value"].Equals("0"))
{
Console.WriteLine(item["File"]);
Console.WriteLine(item["Value"]);
//var JSON1 = JsonConvert.SerializeObject(json1, Newtonsoft.Json.Formatting.Indented);
}
else
{
Console.WriteLine(item["File"]);
Console.WriteLine(item["Value"]);
//var JSON2 = JsonConvert.SerializeObject(json2, Newtonsoft.Json.Formatting.Indented);
}
}
catch(Exception e)
{
Console.WriteLine("Exception is : " + e);
}
/*
Console.WriteLine(item["id"]);
Console.WriteLine(item["File"]);
Console.WriteLine(item["Value"]);
*/
}
Here, I trying to compare sting value with JArray using the above code. But, Here It's not show anything as well not showing exception. It does not enter inside both if condition. Does anyone know how to compare JArray With the String/Integer value and make a separate(As it is) JSON like above?