Objective c 在iOS 4上运行的NSJSONSerialization
我在这里遗漏了什么:Objective c 在iOS 4上运行的NSJSONSerialization,objective-c,ios,Objective C,Ios,我在这里遗漏了什么: + (id) JSONObjectWithData:(NSData *)data { #if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000 //iOS < 5 didn't have the JSON serialization class return [data objectFromJSONData]; //JSONKit #else NSError *jsonParsingError
+ (id) JSONObjectWithData:(NSData *)data {
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000
//iOS < 5 didn't have the JSON serialization class
return [data objectFromJSONData]; //JSONKit
#else
NSError *jsonParsingError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
return jsonObject;
#endif
}
+(id)JSONObjectWithData:(NSData*)数据{
#如果IPHONE操作系统版本允许的最大值小于50000
//iOS<5没有JSON序列化类
返回[data objectFromJSONData];//JSONKit
#否则
N错误*jsonParsingError=nil;
id jsonObject=[NSJSONSerialization jsonObject WithData:数据选项:0错误:&jsonParsingError];
返回jsonObject;
#恩迪夫
}
我在BaseSDK5.0上编译,部署版本是4.0。当我在带有4.2.1的iPhone 3G上运行它时,我得到
dyld:找不到符号:_OBJC_CLASS_$\u NSJSONSerialization
启动时崩溃…。\n如果在编译时计算IPHONE版本的最大允许值<50000
。如果使用iOS 5 SDK编译代码,则条件将为false。不管怎样,都将使用NSJSONSerialization代码
您应该检查NSJSONSerialization
类是否存在。像这样:
+ (id) JSONObjectWithData:(NSData *)data {
Class jsonSerializationClass = NSClassFromString(@"NSJSONSerialization");
if (!jsonSerializationClass) {
//iOS < 5 didn't have the JSON serialization class
return [data objectFromJSONData]; //JSONKit
}
else {
NSError *jsonParsingError = nil;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonParsingError];
return jsonObject;
}
return nil;
}
+(id)JSONObjectWithData:(NSData*)数据{
类jsonSerializationClass=NSClassFromString(@“NSJSONSerialization”);
如果(!jsonSerializationClass){
//iOS<5没有JSON序列化类
返回[data objectFromJSONData];//JSONKit
}
否则{
N错误*jsonParsingError=nil;
id jsonObject=[NSJSONSerialization jsonObject WithData:数据选项:0错误:&jsonParsingError];
返回jsonObject;
}
返回零;
}
当我从xcode运行代码时,它工作了,但是当通过iOS 4.3.1上的testflight安装时,应用程序崩溃了。下面是崩溃日志所说的:找不到符号:_OBJC_CLASS_$_NSJSONSerialization你能不能检查一下[NSJSONSerialization CLASS]!=无