开发者

Iphone JSON-Framework

开发者 https://www.devze.com 2023-02-02 17:01 出处:网络
is posible using JSON-Framework for Iphone to know 开发者_开发问答if a tag exists inside the JSON like in JAVA with the function hasTag(String)?If by tag you mean name/key and you’re using SBJSON, us

is posible using JSON-Framework for Iphone to know 开发者_开发问答if a tag exists inside the JSON like in JAVA with the function hasTag(String)?


If by tag you mean name/key and you’re using SBJSON, use -objectForKey: and test if the return value is nil. For instance, if person is an NSDictionary instance returned by the JSON parser and it can optionally contain a nickname,

if ([person objectForKey:@"nickname"] != nil)
{
    // `nickname' is available; do something with it
}


The way I think to do it is to convert your JSON Object to an NSDictionary and after that use the method -(NSArray *)allKeys, or -(NSArray *)allValues depending what you want. It returns an array with all the keys (or values) inside the object. You can then compare the keys with the one you want to find.

Hope it helps you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号