zoukankan      html  css  js  c++  java
  • Paste JSON as Code • quicktype 软件的使用

    1、软件图标认知

    • 该软件为json字符串与对象之间相互转户的自动化软件。
    • 下载地址

    2、打开软件

    • 配置基本设置

    3、生成.h文件

    • 选择生成.h文件
    • 拷贝代码到你管理该对象json文件的.h文件下

    4、生成.m文件

    • 选择生成.m文件
    • 拷贝代码到你管理该对象json文件的.m实现文件下

    5、代码实际测试

    • 5.1 获取json字符串

      • 这里json字符串存储在文件中
    • 5.2 操作代码

      /************ 读取桌面文件测试Json *****************************/
      - (void)readFilesToTestJson {
          
          NSString *thepath = @"/Users/lelight/Desktop/jsonFile.txt";
          if ([[NSFileManager defaultManager] fileExistsAtPath:thepath]) {
              NSData *data = [[NSData alloc] initWithContentsOfFile:thepath];
              
              NSError *error = nil;
              CH_GetAquariumLampCustomDataItemArray *dataItemArray = CH_GetAquariumLampCustomDataItemArrayFromData(data, &error);
              CHLog(@"json转对象 %@", dataItemArray);
              
              for (CH_GetAquariumLampCustomDataItemArrayElement *dataItem in dataItemArray) {
                  CHLog(@"json对象 week %@", dataItem.week);
              }
              
              NSString *jsonString = CH_GetAquariumLampCustomDataItemArrayToJSON(dataItemArray, NSUTF8StringEncoding, &error);
              CHLog(@"对象转json %@", jsonString);
              
              CH_GetAquariumLampCustomDataItemArray *dataItemArrayB = CH_GetAquariumLampCustomDataItemArrayFromJSON(jsonString, NSUTF8StringEncoding, &error);
              CHLog(@"json转对象 %@", dataItemArrayB);
              
              NSData *jsonStringB = CH_GetAquariumLampCustomDataItemArrayToData(dataItemArrayB, &error);
              CHLog(@"对象转json %@", jsonStringB);
              
              [CHTCPCustomDataItem shareInstance].dataItemArray = dataItemArray;
          }
          else {
              NSLog(@"文件不存在");
          }
      }
      
    • 5.3 实际效果

  • 相关阅读:
    jQuery+ThinkPHP+Ajax实现即时消息提醒功能
    依赖注入(DI)
    控制反转(IoC)
    ajax以base64上传图片到django
    python 多进程、多线程、协程
    python3 实现tcp/udp局域网通信
    同源策略与跨域访问
    nginx+uwsgi阿里云ubuntu服务器上简单部署flask RESTful风格项目
    python3 实现 websocket server 解决中文乱码
    python IO 多路复用 epoll简单模型
  • 原文地址:https://www.cnblogs.com/CH520/p/9969890.html
Copyright © 2011-2022 走看看