lundi 2 novembre 2015

How to save Json file using iTunes

How can i save these infos as a file using iTunes to download or see the results.. Ideas? //json output

- (void)showInfos {
NSMutableDictionary *infoDictionary = [[NSMutableDictionary alloc]init];
[infoDictionary setObject:self.totalDuration.text forKey:@"totalFrames"];

NSMutableArray *nodesArray = [[NSMutableArray alloc]init];
[nodesArray addObject:@{@"x":@(_zeroButton.frame.origin.x),@"y":@(_zeroButton.frame.origin.y),@"frame":self.zeroBtnLbl.text}];
[nodesArray addObject:@{@"x":@(_firstButton.frame.origin.x),@"y":@(_firstButton.frame.origin.y),@"frame":self.firstBtnLbl.text}];
[nodesArray addObject:@{@"x":@(_secondButton.frame.origin.x),@"y":@(_secondButton.frame.origin.y),@"frame":self.secondBtnLbl.text}];
[nodesArray addObject:@{@"x":@(_thirdButton.frame.origin.x),@"y":@(_thirdButton.frame.origin.y),@"frame":self.thirdBtnLbl.text}];
[nodesArray addObject:@{@"x":@(_fourthButton.frame.origin.x),@"y":@(_fourthButton.frame.origin.y),@"frame":self.fourthBtnLbl.text}];
[infoDictionary setObject:nodesArray forKey:@"nodes"];

NSLog(@"dicArray:%@",infoDictionary);
NSData *data = [NSJSONSerialization dataWithJSONObject:infoDictionary options:kNilOptions error:nil];
NSArray *retDicArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"retDicArray:%@",retDicArray);

//    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:infoDictionary options:kNilOptions error:nil];
NSString *docDir   = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [docDir stringByAppendingPathComponent:@"data.json"];
[data writeToFile:filePath atomically:YES];
}

Aucun commentaire:

Enregistrer un commentaire