摘要:json字符串转对象-----先把json字符串UTF8编码成data,再用data转成对象

ios 生成json数据 ios json转字符串_后台返回数据中含json字符串

NSArray * arr = [self jsonObject:model.MESSAGE_CONTENT];
• (id)jsonObject:(NSString *)str {
 str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@"\n"];
 str = [str stringByReplacingOccurrencesOfString:@"\r" withString:@"\r"];
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
 return [self jsonObjectFromData:data];
 }• (id)jsonObjectFromData:(NSData *)data {
 NSError *error = nil;
 return [NSJSONSerialization JSONObjectWithData:data
 options:0
 error:&error];
 }