我下载框架JSON,添加到我的项目,我认为它是正确添加因为我放
#import
我没有任何警告.但是,当我想使用它时,问题就开始了:
NSMutableDictionary * attachement = [NSMutableDictionary dictionary]; NSString *requestJson = [attachement JSONRepresentation];
但我对JSONRepresentation有一个警告:
Instance method '-JSONRepresentation' not found (return type defaults to 'id')
我该如何解决?
谢谢
如果您使用的是iOS 5.0及更高版本,请使用内置版本 NSJSONSerialization
NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:attachement options:NSJSONWritingPrettyPrinted error:&error]; if (!jsonData) { //Deal with error } else { NSString *requestJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; }