- Due to the convenience of development, sometimes it is necessary to print NSDictionary through NSLog. For example, when the production environment is pushed, we cannot directly break the point debugging, so we extract a method for printing convenience:
2.
-(NSString*)DataTOjsonString:(id)object
{
NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
Reprinted from: http://blog.csdn.net/yi_zz32/article/details/52354935