how i can check NSDictionary
key value is null ?
i am using ASIHttpRequest
:
NSDictionary *tempDict=[[[request responseString] JSONValue] valueForKey:@"data"];
if key value is "0 key/value pair" and crease please give me a answer.
thank you.
how i can check NSDictionary
key value is null ?
i am using ASIHttpRequest
:
NSDictionary *tempDict=[[[request responseString] JSONValue] valueForKey:@"data"];
if key value is "0 key/value pair" and crease please give me a answer.
thank you.
you can check if the key is exists inside NSDictionary like this:
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Ron",@"first_name",@"25",@"age", nil];
if([self dictionary:dict containsKey:@"age"])
{
// Key exists
}
else
{
// Key does not exists
}
Use this helper function :
-(BOOL)dictionary:(NSDictionary *)dictionary containsKey:(id)key
{
if(dictionary != nil)
{
if([dictionary objectForKey:key])
{
return YES;
}
}
return NO;
}
You should check NSDictionary key values before access it. Put a condition with same key if it contains any not null value than proceed else take a precaution.