I have a JSON object. I want to determine whether or not it contains only a specific key. Here is the code:
{
"Name": "ThirdParty",
"Categories": [
{ "Name": "Identity" },
{
"Name": "Contact Information",
"Mandatory": true,
"Fields": [
{ "Name": "Phones" },
{ "Name": "Faxes" },
{ "Name": "Emails" }
]
},
{ "Name": "Addresses" },
{ "Name": "Bank Accounts" }
]
}
I want to determine for each category whether or not it consists of the Name
key only. Using this answer, I believe the solution should look something like this:
foreach(dynamic category in jObject.Categories)
{
var result = category.Children().Except(/* What goes here? */).Any();
}
But what should exactly go in the Except()
method? Is there a better way of doing this? Thanks.
Note: This is not a duplicate of the following questions:
How to determine if a Javascript object has only one specific key-value pair? (my question is about C#, not JavaScript).
Determining whether a JSON object contains a specific fieldname in jQuery (my question is about C#, not jQuery, and it's not about whether a "fieldname" exists in an object. It's about whether a key is the only one that exists in an object).