• 该软件为json字符串与对象之间相互转户的自动化软件。
  • 下载地址
    Paste JSON as Code • quicktype 软件的使用

2、打开软件

  • 配置基本设置
    Paste JSON as Code • quicktype 软件的使用

3、生成.h文件

  • 选择生成.h文件
  • 拷贝代码到你管理该对象json文件的.h文件下
    Paste JSON as Code • quicktype 软件的使用
    Paste JSON as Code • quicktype 软件的使用

4、生成.m文件

  • 选择生成.m文件
  • 拷贝代码到你管理该对象json文件的.m实现文件下
    Paste JSON as Code • quicktype 软件的使用
    Paste JSON as Code • quicktype 软件的使用

5、代码实际测试

  • 5.1 获取json字符串

    • 这里json字符串存储在文件中
      Paste JSON as Code • quicktype 软件的使用
  • 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 实际效果

    Paste JSON as Code • quicktype 软件的使用

相关文章:

  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2021-08-03
  • 2021-07-01
  • 2022-12-23
  • 2021-04-24
  • 2022-12-23
猜你喜欢
  • 2021-07-16
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案