我有一个像这样的json对象:
{
"Name": "Mike",
"Personaldetails": [
{
"Age": 25,
"Surname": "Barnes"
}
],
"Address": [
null
]
}
现在我已经编写了 C# 来访问此代码并遍历数组中的每个对象"Personal Details"
并进入"Address"
数组。
我将如何编写检查以查看数组是否为空?
dynamic jsonObject = JsonConvert.DeserializeObject(data);
foreach (var obj in jsonObject.Personaldetails)
{
if (obj.Age = 24)
{
//do stuff
}
}
//This is where I am stuck
if(jsonObject.Address = null)
{
return "null array";
}
//If another json stream was not null at "Address" array
else
{
foreach (var obj in jsonObject.Address)
{
if (obj.arrayItem == "Something")
{
//do stuff
}
}
}