Paste JSON as Code ? quicktype 软件的使用
Posted CH520 -- Cnblogs。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 实际效果

以上是关于Paste JSON as Code ? quicktype 软件的使用的主要内容,如果未能解决你的问题,请参考以下文章
sh never-copy-and-paste-code-from-the-internet-you-dont-understand.sh
通过actionscript3(和as3corelib)获得一个美味的JSON提要
如何在剧情中标题一个大胆的罗马字母
将 QuerySet 作为 JSON 返回?
QUIC协议文档翻译——什么是QUIC
无法快速从 JSON 中正确提取数据