从在线 JSON 文件更新 JSON 本地文件

Update JSON local file from online JSON file

我想在有新版本文件时更新应用程序中的本地 JSON 文件。我有检查是否有新版本的算法。

但是现在,我需要一些代码来 change/update 本地 JSON 在线 JSON。

我建议您使用 .plist 文件,因为它可以轻松存储 NSDictionary 或 NSArray(可以从 JSON 对象转换而来)

试试下面的代码:

//store plist file in documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = paths[0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"localJSON.plist"];
if([responseObject isKindOfClass:[NSArray class]])
{
//its an array
NSArray * dataToStore =  jsonObject;
[dataToStore writeToFile:filePath atomically:YES];
} 
else
{
//its a dictionary
NSDictionary * dataToStore =  jsonObject;
[dataToStore writeToFile:filePath atomically:YES];
}