我需要迭代嵌套的 json 并且需要从最终的 json 对象中提取几个固定的属性值。在下面的 JSON 中,我需要为 title/ref 和其他属性做一些内部逻辑。我怎样才能解析下面的json并得到像这样的键type,employeeFirstName,employeeLastName and address
JSON:
"properties": {
"type": {
"description": "Defines type of object being represented",
"type": "string",
"enum": [
"employee"
]
},
"employeeFirstName": {
"title": "First Name",
"description": "Employee first name",
"type": "string"
},
"employeeLastName": {
"title": "Last Name",
"description": "Employee Last name",
"type": "string"
},
"address": {
"title": "Address",
"description": "Employee present address ",
"$ref": "#/definitions/address"
}
}
代码:
var jsonObject = JObject.Parse(jsonFileContent);
var propertyContent = JObject.Parse(jsonObject["properties"].ToString());
var definitionContent = JObject.Parse(jsonObject["definitions"].ToString());
for (int i = 0; i < propertyContent.Count; i++)
{
// Here I need to pass the value dynamically.
//For Example, first iteration, type needs to be passed,
//in second iteration, employeeFirstName needs to be passed and so on
var tempContent = propertyContent["address"].ToString();
var def = JObject.Parse(tempContent);
for (int j = 0; j < def.Count; j++)
{
//Some working logic is added based on the specific key
}
}
在上面的代码中,我需要在 var tempContent = propertyContent["address"].ToString();每次迭代的步骤中传递动态密钥。那么,有没有办法从propertyContent