JSON<=NSDictionary<=변환=>NSData 유형

699 단어 json
//NSDictionary  ==>NSData  :
NSDictionary *targetDictionary;
NSMutableData *data = [[NSMutableData alloc] init]; 
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject : targetDictionary forKey : @"Custom Key”];
[archiver finishEncoding];
//NSData     NSDictionary  :
NSData *data;
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *myDictionary = [[unarchiver decodeObjectForKey:@"Custom Key"] retain];
[unarchiver finishDecoding];
//NSDictionary  JSON:
NSString *jsonStr=[dict JSONRepresentation];

좋은 웹페이지 즐겨찾기