摘要:json字符串转对象-----先把json字符串UTF8编码成data,再用data转成对象
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];
}