NSJSONSerialization无法识别

1 serialization json objective-c ios

我试图将json字符串解析为字典.为此我使用以下代码:

NSDictionary* json = [NSJSONSerialization JSONObjectWithData:json_string];
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

+[NSJSONSerialization JSONObjectWithData:]: unrecognized selector sent to class...
Run Code Online (Sandbox Code Playgroud)

我在Apples文档中搜索,我看到该类包含在Foundation框架中(我的项目中包含该框架).我不知道为什么会这样.

任何的想法?感谢致敬.

Mar*_*n R 10

你忘了一些论点:

NSError *error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:json_string options:0 error:&error];
Run Code Online (Sandbox Code Playgroud)

请注意,第一个参数是一个NSData对象,而不是一个字符串.