1.字串轉字典
NSString * jsonString = @“123”;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
複製程式碼
2.字典轉字串
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic
options:NSJSONWritingPrettyPrinted
error:&parseError];
NSString * str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
複製程式碼