hello all,
There is few post how to use isNullorempty but never managed to work
Im getting Json object , loop though it , but when i have null value or missing properties
i got this msg “If: Object reference not set to an instance of an object” which is normal,
but couldnt figure out how to skip it (i have a flag need to change the value of its null or empty)
Check for the response being received.
Json objects have children in in, so you can check for its count.
If jobj.count>0
then proceed with steps
else
log message, no data found.
Basically what you need to do is, Check for specific keys if they exist or not in the JObject, if the key does exist, basis that you need to consider whether is coming with isNullOrEmpty to determine blank/no values for the key.
Not sure the exact syntax for a JSON object, but for a dictionary here is how you do it. In your IF condition you check if the key exists, and use the AndAlso operator to then check if it’s null:
The AndAlso operator will ONLY process the part after it if the part before it is true. So if the someKey key doesn’t exist, (ContainsKey returns false) then the IsNullOrEmpty won’t throw the object reference error.