我在运行时在objective-c中有一个对象,我只知道KVC键,我需要检测此属性的返回值类型(例如,我需要知道它是NSArray还是NSMutableArray),我该怎么做呢?
我一直在寻找是否有可能获得一个JSON字典或数组,并直接将它映射到一个自定义对象,其属性与JSON标签的名称相同,但我找不到任何有关它的信息.
我一直在手动解析JSON字典,如下所示:
id deserializedObj = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingAllowFragments
error:&error];
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *jsonDictionary = (NSDictionary *)jsonObject;
if ([jsonDictionary objectForKey:idTag] != [NSNull null])
[myObject setID:[[jsonDictionary objectForKey:@"id"] integerValue]];
// Rest of properties
}
Run Code Online (Sandbox Code Playgroud)
但我觉得奇怪的是必须手动解析每个字典条目而没有办法直接将其序列化为自定义对象,是不是还有其他更快的方法?
注意:我需要我的应用程序与iOS 5+兼容
提前致谢