Eletfds
Eletfds

Reputation: 11

Problem Saving json to .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];

I intend to save the json parse to a data.plist for use later, but is not saving

Upvotes: 1

Views: 1314

Answers (2)

Muhammed Basil
Muhammed Basil

Reputation: 1834

I tried both methods.I got the following results:

filepath (1) :/Users/user/Library/Application Support/iPhone Simulator/5.0/Applications/CFADAD22-F041-4F6D-9B50-70C140372D06/FlipView.app/apiData.plist

filepath(2) :/Users/user/Library/Application Support/iPhone Simulator/5.0/Applications/CFADAD22-F041-4F6D-9B50-70C140372D06/Documents/apiData.plist

but i couldn't find plist file in any of the locations.

What may be problem here?

Upvotes: 3

NSExplorer
NSExplorer

Reputation: 12149

The method pathForResource:ofType: is used to retrieve the path of existing files/resources and NOT to create new file paths

Try this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myFile.plist"];
[myDictionary writeToFile:path atomically:YES];

Upvotes: 1

Related Questions