1. 程式人生 > >Paste JSON as Code ? quicktype 軟件的使用

Paste JSON as Code ? quicktype 軟件的使用

odata use 文件 image sat nts else instance 基本設置

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 實際效果

    技術分享圖片

Paste JSON as Code ? quicktype 軟件的使用