ios nsdata怎么转换son
2个回答
展开全部
NSData转Json:先将NSData转成字典,再将字典转成Json
例如:
1、NSData转字典
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *myDictionary = [[unarchiver decodeObjectForKey:@"Some Key Value"]];
[unarchiver finishDecoding];
2、字典转Json
NSString *jsonStr=[myDictionary JSONRepresentation];
例如:
1、NSData转字典
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *myDictionary = [[unarchiver decodeObjectForKey:@"Some Key Value"]];
[unarchiver finishDecoding];
2、字典转Json
NSString *jsonStr=[myDictionary JSONRepresentation];
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询