I have a json object like so:
{
"Name": "Mike",
"Personaldetails": [
{
"Age": 25,
"Surname": "Barnes"
}
],
"Address": [
null
]
}
Now I have written C# to access this code and iterate over each object in the "Personal Details" array and into "Address" array.
How would I write a check to see if the array is null?
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
}
}
}
Personaldetailsproperty's value).Newtonsoft.Json.Linq.JObjectdoes not contain a definition for Personaldetails. Are you using JSON.NET?