1

I have json file like this :

 {"fileContent":[{"name":"aaaa","type":"file","ext":"sql","modified":"2013\/04\/11 - 04:29","created":"2013\/04\/11 - 04:29","size":"1460","dirid":"5"},    {"name":"directory02","type":"file","ext":"sql","modified":"2013\/04\/11 -  04:29","created":"2013\/04\/11 - 04:29","size":"1577","dirid":"6"}, {"name":"index2","type":"file","ext":"php","modified":"2013\/04\/11 -  05:06","created":"2013\/04\/11 - 05:06","size":"9932","dirid":"8"}, {"name":"directorffdsgfg","type":"file","ext":"sql","modified":"2013\/04\/11 -    10:00","created":"2013\/04\/11 - 10:00","size":"1577","dirid":"10"}, {"name":"directory02","type":"file","ext":"sql","modified":"2013\/04\/11 -  12:10","created":"2013\/04\/11 - 12:10","size":"1577","dirid":"11"},{"name":"jquery- mousewheel-master","type":"file","ext":"zip","modified":"2013\/04\/11 -  12:10","created":"2013\/04\/11 - 12:10","size":"5213","dirid":"12"},{"name":"perfect-scrollbar-master","type":"file","ext":"zip","modified":"2013\/04\/11 -  12:10","created":"2013\/04\/11 - 12:10","size":"11867","dirid":"13"}, {"name":"E_PDF","type":"file","ext":"png","modified":"2013\/04\/17 -  09:15","created":"2013\/04\/17 - 09:15","size":"7467","dirid":"24"}, {"name":"filefolder_H.PNG","type":"file","ext":"png","modified":"2013\/04\/17 -  09:15","created":"2013\/04\/17 - 09:15","size":"10575","dirid":"25"}],"folderContent": [{"name":"Folder 2","type":"folder","ext":"sql","modified":"2013\/04\/11 -  05:04","created":"2013\/04\/11 - 05:04","size":"1577","dirid":"7"},{"name":"Folder  1","type":"folder","ext":"zip","modified":"2013\/04\/15 - 09:08","created":"2013\/04\/15 -  09:08","size":"11867","dirid":"14"}],"files":9,"folders":2}

and store this in NSDictionary with name titles. (down code show it:)

NSDictionary *titles = [NSJSONSerialization JSONObjectWithData:Data options:kNilOptions error:nil];

and I read fileContent value from titles and store them in NSMutableArray with name "all" like this code:

NSArray *fileContent = [titles objectForKey:@"fileContent"];
NSMutableArray *all = [[NSMutableArray alloc]init];
[all addObjectsFromArray:fileContent];

I want store 2 value (name & type) from "all" in .plist file but I dont know how do it?

janatan
  • 415
  • 2
  • 5
  • 11
  • possible duplicate of [how to store json data from url in ios device and to use local it](http://stackoverflow.com/questions/16141308/how-to-store-json-data-from-url-in-ios-device-and-to-use-local-it) – rckoenes Apr 22 '13 at 08:19
  • I ask different question in another post – janatan Apr 22 '13 at 08:33

1 Answers1

1

Try

NSDictionary *titles = [NSJSONSerialization JSONObjectWithData:Data options:kNilOptions error:nil];

NSArray *fileContent = [titles objectForKey:@"fileContent"];
NSMutableArray *all = [fileContent mutableCopy];

NSMutableArray *folders = [NSMutableArray array];
[all enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
     NSDictionary *folder = (NSDictionary *)obj;

     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
     [dict setObject:folder[@"name"] forKey:@"name"];
     [dict setObject:folder[@"type"] forKey:@"type"];

     [folders addObject:dict];

 }];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths[0]; 
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Folders.plist"];

[folders writeToFile:filePath atomically:YES];
Anupdas
  • 10,211
  • 2
  • 35
  • 60