Reputation: 5699
I am unable to check if one of my keys is empty.
Following is the parsed JSON response I am working with :
Case 1 (key 'tags' is not empty)
{
height = 480;
pid = "a@bsioihf93u420934";
tags = (
{
attributes = {
mood = {
confidence = 42;
value = happy;
};
smiling = {
confidence = 52;
value = false;
};
};
center = {
x = "49.86";
y = "60.52";
};
confirmed = 0;
width = "50.28";
}
);
url = "http://abc/efg/hijk/lmnop.jpg";
width = 360;
}
There are times when the response looks like the following :
Case 2 (key 'tags' is empty)
{
height = 480;
pid = "a@bsioihf93u420934";
tags = (
);
url = "http://abc/efg/hijk/lmnop.jpg";
width = 360;
}
When I check if 'tags' is empty in case 2, it returns false :
if ([photo objectForKey:@"tags"] == nil)
Checking the actual value of [photo objectForKey:@"tags"]
in logs returns :
(
)
How else can I check if 'tags' is empty ?
Upvotes: 0
Views: 1766
Reputation: 1412
How exactly are you parsing and storing the JSON text? It looks like maybe you are storing it into an NSArray/NSDictionary (maybe)? A little clarification on how it is being parsed and what data structure is storing it would help.
Assuming that you are storing it in an NSArray/NSDictionary, what is wrong/not working with the way you are currently checking if "tags" is empty?
If
if ([photo objectForKey:@"tags"] == nil)
is returning false in case one and true in case two, that means that there is no value in the data structure for the key "tags" in case two, which means the "tags" field is empty.
That actually seems like the best and most practical way to check.
Upvotes: 0