iOS各类型转换
2017-01-02 本文已影响0人
250ZH
//UIIamge 转 NSData
UIIamge *image = [UIImage imageNamed:@"imageName.png"];
NSData *imageData = UIImagePNGRepresentation(image]);
//NSData 转 UIIamge
NSData *data;
UIImage *image = [UIImage imageWithData:data];
//JSON字符串 转 NSDictionary
/*
NSJSONReadingOptions:
NSJSONReadingMutableLeaves
NSJSONReadingMutableContainers
NSJSONReadingAllowFragments
*/
NSString *string = @"{\"userId\":1,\"userName\":\"username\",\"nickName\":\"nickname\"}";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];