Ich habe folgende Json:Validieren Json Keys
{
"requirements": {
"-FileName": "sample.xls",
"requirement": [
{
"desc": "Employee status will be classified as:
• Assigned $ when employee is working on a project.
• Reserved when employee is scheduled to work on a project in near future. Unassigned when employee is not working on project.",
"Id": "Req40"
},
{
"Id": "NFR-2",
"desc": "Team Leader should create resource allocation $% request in Maintain Project Module. Resource allocation request [email protected] associated with only one role. Project [email protected] Manager should provide roll-on date and roll-off date in resource allocation request."
},
{
"Id": "req2",
"desc": "PRMS must always be available except during the & @ scheduled maintenance. Scheduled maintenance must always be at 8PM on week days.",
"message": "message of Req3"
}
]
}
}
Ich möchte überprüfen, ob es Id Und Desc Tags oder Schlüssel in die er enthält.
habe ich versucht, Code unten: -
try
{
var obj = Newtonsoft.Json.Linq.JToken.Parse(strInput);
if(obj["Id"]!=null)
return true;
else
return false;
}
catch (JsonReaderException jex)
{
Logger.GetInstance().LogException(jex, jex.StackTrace, Category.General);
return false;
}
Aber dieser Code gibt obj [ "id"] als null, selbst wenn Id in Json vorhanden ist.
Nun ja, Ihr JSON enthält keine Top-Level 'Id' Eigenschaft - es hat eine' requirements' Eigenschaft enthält, die dann eine 'requirement' Eigenschaft hat Dies ist ein Array von anderen Objekten, von denen jedes eine Id-Eigenschaft besitzt. –