美文网首页iOS 笔记
iOS各类型转换

iOS各类型转换

作者: 250ZH | 来源:发表于2017-01-02 10:53 被阅读0次


    //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];

    相关文章

      网友评论

        本文标题:iOS各类型转换

        本文链接:https://www.haomeiwen.com/subject/kitfsttx.html