OC 字符串和字典的相互转化
1.字符串转字典
NSString * jsonString = @"";
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
2.字典转字符串
SData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
NSString * str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
posted on 2018-11-06 20:22 yucaijiang 阅读(3183) 评论(0) 编辑 收藏 举报