zoukankan      html  css  js  c++  java
  • 常见序列化与反序列化方法

    1  // 对图片要求不高的时候建议用jpg,要求比较高的时候用png
    2  // 方式一:
    3  // let imageData = UIImagePNGRepresentation(image)!
    4  // 方式二:
    5  // 参数2(compressionQuality):质量系数0-1,越大图片质量越高,越清晰
    6  let imageData = UIImageJPEGRepresentation(image, 0.5)!
    7  // 写出文件,对比,可以看出jpg压缩的比较大,压缩后的图片比较模糊
    8  (imageData as NSData).write(toFile: "/Users/yaoshuai/Desktop/1.png", atomically: true)
     1 // 反序列化,返回值为id
     2     // NSJSONSerialization JSONObjectWithData:<#(nonnull NSData *)#> options:<#(NSJSONReadingOptions)#> error:<#(NSError * _Nullable __autoreleasing * _Nullable)#>
     3     
     4     // 序列化,返回值为NSData
     5     // NSJSONSerialization dataWithJSONObject:<#(nonnull id)#> options:<#(NSJSONWritingOptions)#> error:<#(NSError * _Nullable __autoreleasing * _Nullable)#>
     6     
     7     // NSData -> NSString
     8     // [NSString alloc] initWithData:<#(nonnull NSData *)#> encoding:<#(NSStringEncoding)#>
     9     
    10     // NSData -> NSProperty
    11     // NSPropertyListSerialization propertyListWithData:<#(nonnull NSData *)#> options:<#(NSPropertyListReadOptions)#> format:<#(nullable NSPropertyListFormat *)#> error:<#(out NSError * _Nullable __autoreleasing * _Nullable)#>
    1     NSString *urlString = @"https://www.baidu.com?userName=中国";
    2     
    3     // NSString -> NSData
    4     NSData *data = [urlString dataUsingEncoding:NSUTF8StringEncoding];
  • 相关阅读:
    MySQL主从复制原理
    MySQL调优
    apache禁止php解析--安全
    apache禁止指定的user_agent访问
    python---日常练习
    字符、字节的概念和区别;编码概念
    Django模型初识
    git安装
    Django--Hello
    fillder---断言/打断点,更改提交数据
  • 原文地址:https://www.cnblogs.com/panda1024/p/6283228.html
Copyright © 2011-2022 走看看