2

你们中的任何人都知道如何将 json 数据调用保存到文件中吗?

self.results=[NSJSONSerialization
                           JSONObjectWithData:jsonData
                           options:0
                           error:&error];

我试过了:

 [_results writeToFile:@"jsonFile" atomically:YES];

但我没有看到文件:

NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:directory error:&error];

file path (
    "Default-568h@2x.png",
    "Default.png",
    "Default@2x.png",
    "en.lproj",
    "Info.plist",
    "JSON Generator",
    PkgInfo
)

你们中的任何人都知道我在做什么错吗?

我会非常感谢你的帮助

4

1 回答 1

1

JSONObjectWithData返回 anNSArrayNSDictionarynil。如果不是 nil 写它:

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
于 2012-12-31T23:19:14.787 回答