我对NSDictionary非常缺乏经验。我有这个数据结构:
{"aps":
{"alert":null},
"custom_control":
{"type":"topic_comment",
"object":
{"topic_id":"1","topic_section":"2","plan_id":"3","user_id":"4"}
}
}
通过这样做,我可以获得“aps”值:
NSString *aps = [dictionary objectForKey:@"aps"];
但是由于aps包含一个项目数组,我应该使用什么数据结构而不是NSString?我如何获取custom_control的值和“object”
中的值谢谢!
答案 0 :(得分:1)
NSDictionary *dict_object = [[dictionary objectForKey:@"custom_control"]objectForKey:@"object"];
这是您词典的精确层次结构
您的NSDictionary(Keys:aps,custom_control)
(i).aps
(i.i)NSDictionary(key:alert)
(ii).custom_control
(ii.i)NSDictionary(keys:type,object)
(ii.i.i)NSString(key:topic_comment)
(ii.i.ii)NSDictionary(keys:topic_id,topic_section,plan_id,user_id)
请参阅此link