在我的 iOS 5.1 应用程序中,我尝试将 JSON 文本文件加载到 NSDictionary 中。
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"stuff" ofType:@"json"];
NSDictionary *stuff = [NSDictionary dictionaryWithContentsOfFile:filepath];
文件路径有效,文件存在,但内容nil
,这意味着解码文件时出现问题(根据 documentation )。
(如何)我可以获得更多有关为什么 [NSDictionary DictionaryWithContentsOfFile:]
- 或任何类型的 API 调用 - 返回 nil
的调试信息吗?
最佳答案
将内容读取为 NSData
,然后使用 +[NSPropertyListSerialization propertyListWithData:options:format:error:]
。
关于iOS - 如何获取有关 nil 返回值的更多调试信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10911230/