2
内のタグをチェックするためのLINQを使用する方法: -私はJSONファイルの下に持ってJSON
私は、「ID」と「DESC」以外のタグはJSON形式で存在しているかどうかを確認したい{
"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"
}
]
}
}
。私は以下のようにループのために使用されている。このため
: - 私はforループを使用せずにそれを最適化するにはどうすればよい
for (int i = 0; i < NumberOfRequirements; i++)
{
int NumberOfTagsInJson = (obj["requirements"]["requirement"][i]).Count();
if (NumberOfTagsInJson == 2) // checks if tag other than id and desc is present Eg. Message
{
var id = obj["requirements"]["requirement"][i]["Id"];
if (id == null)
{
IsHavingValidTags = false;
break;
}
var Desc = obj["requirements"]["requirement"][i]["desc"];
if (Desc == null)
{
IsHavingValidTags = false;
break;
}
}
else
{
IsHavingValidTags = false;
break;
}
}
。 例私は、「ID」と「DESC」以外のタグが存在しているかどうかを確認するためのLINQを使用していた
この後(obj["requirements"]["requirement"]).ToList()
- :として私はリストに変換しようとしました。
どうすれば使用できますか?
EDIT 1
それがエラーを与えている:-expressionはLmbda式を含めることはできません。.. EDIT1 –
が完了参照してください...それを理解しました時計のウィンドウから見ることができません..ありがとうこの作品 –
こんにちは、これで私を助けてください: - http://stackoverflow.com/questions/40798228/check-all-properties-in-list –