我已经在几个项目中使用过它......
[NSJSONSerialization dataWithJSONObject:someObject options:0 error:nil]
但我不知道如何指定no options。这既适用于阅读,也适用于写作。
我在某个地方看到了一个例子,这个人使用了一个常量值,而不是只是,0但我找不到它。
有没有办法正确指定没有选项?
如果我使用上述代码,AppCode 会显示警告。
我已经在几个项目中使用过它......
[NSJSONSerialization dataWithJSONObject:someObject options:0 error:nil]
但我不知道如何指定no options。这既适用于阅读,也适用于写作。
我在某个地方看到了一个例子,这个人使用了一个常量值,而不是只是,0但我找不到它。
有没有办法正确指定没有选项?
如果我使用上述代码,AppCode 会显示警告。
You can use kNilOptions. Ray Wenderlich uses it in his iOS JSON tutorial, and I've used it without issues.
kNilOptions is defined in MacTypes.h:
enum {
kNilOptions = 0
};
Since NSJSONReadingOptions is an enum, kNilOptions is suitable, and as Ray Wenderlich points out in the tutorial, it's more descriptive than simply 0:
NSDictionary *dictionary = [NSJSONSerialization dataWithJSONObject:someObject
options:kNilOptions
error:nil];
选项 0 很好,这就是我在 Xcode 中使用的。它不抱怨。