将json保存到.plist时出现问题

问题描述

|
-(IBAction)buttonlogin:(id)sender
{



    Nsstring *samplejson=@\"http://www.colorysabor.com/sample.json\";

    NSData *flickrData=[NSData dataWithContentsOfURL:[NSURL URLWithString:samplejson]];
    NSError *theError = nil;

    NSMutableDictionary *theObject = [[NSMutableDictionary alloc] init];
    theObject =[[CJSONDeserializer deserializer] deserialize:flickrData error:&theError];



NSLog(@\"Result: %@\",theObject);

    NSBundle *bundle = [NSBundle mainBundle];
    Nsstring *filePath = [bundle pathForResource:@\"data\" ofType:@\"plist\"];


    [theObject writetoFile:filePath atomically:YES];
我打算将json解析保存到data.plist中,以供以后使用,但不保存     

解决方法

我尝试了两种方法,结果如下: 文件路径(1):/用户/用户/库/应用程序支持/ iPhone Simulator / 5.0 / Applications / CFADAD22-F041-4F6D-9B50-70C140372D06 / FlipView.app / apiData.plist filepath(2):/ Users /用户/ Library / Application Support / iPhone Simulator / 5.0 / Applications / CFADAD22-F041-4F6D-9B50-70C140372D06 / Documents / apiData.plist 但我在任何位置都找不到plist文件。 这可能是什么问题?     ,方法“ 1”用于检索现有文件/资源​​的路径,而不用于创建新文件路径 尝试这个:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@\"myFile.plist\"];
[myDictionary writeToFile:path atomically:YES];