NSMutableDictionary和JSONRepresentation

use*_*903 -1 json frameworks ios

我下载框架JSON,添加到我的项目,我认为它是正确添加因为我放

#import <JSON/JSON.h>
Run Code Online (Sandbox Code Playgroud)

我没有任何警告.但是,当我想使用它时,问题就开始了:

NSMutableDictionary * attachement = [NSMutableDictionary dictionary];
NSString *requestJson = [attachement JSONRepresentation];
Run Code Online (Sandbox Code Playgroud)

但我对JSONRepresentation有一个警告:

Instance method '-JSONRepresentation' not found (return type defaults to 'id')
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

谢谢

Sta*_*ash 13

如果您使用的是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];
}
Run Code Online (Sandbox Code Playgroud)