I have a problem when Extracting data from a Dictionary object. Count of the Dictionary is displaying as 1, but the one value it is displaying is null. I want to display a AlertView when there is no data in the Dictionary object. I thought of displaying the AlertView when the count is '0', but it returning '1'.
I am extracting this dictionary object from a WebService using JSON.
{
"My Data" = null;
}
Used this code for getting the "My Data" value into the Dictionary variable Datas.
Datas = (NSDictionary *) [details objectForKey:@"My Data"];
if ([Datas count] == 0) {
//code for showing AlertView....
}
Please help me to display a UIAlertView when the Dictionary value having null....
NSDictionary
and other collections cannot contain nil
values. When NSDictionary
must store a null
, a special value [NSNull null]
is stored.
Compare the value at @"My Data"
to [NSNull null]
to determine if the corresponding value is null
or not.
// Since [NSNull null] is a singleton, you can use == instead of isEqual
if ([details objectForKey:@"My Data"] == [NSNull null]) {
// Display the alert
}
Usually null values in JSON get parsed to NSNull
. So this condition should check for that as well as nil: if((details[@"My Data"] == nil) || (details[@"My Data"] == [NSNull null]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With