Paste JSON as Code ? quicktype 软件的使用
Posted CH520 -- Cnblogs。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Paste JSON as Code ? quicktype 软件的使用相关的知识,希望对你有一定的参考价值。
1、软件图标认知
- 该软件为json字符串与对象之间相互转户的自动化软件。
- 下载地址
![](https://image.cha138.com/20210527/b5393b54549f424f89509fa08bcaeddb.jpg)
2、打开软件
- 配置基本设置
![](https://image.cha138.com/20210527/b3efd77dd3a343138aa5d8176f748256.jpg)
3、生成.h文件
- 选择生成.h文件
- 拷贝代码到你管理该对象json文件的.h文件下
![](https://image.cha138.com/20210527/b23f021bd2774f66bf1abb362114b29e.jpg)
![](https://image.cha138.com/20210527/3d32b483106043e5964e28fb52afdffa.jpg)
4、生成.m文件
- 选择生成.m文件
- 拷贝代码到你管理该对象json文件的.m实现文件下
![](https://image.cha138.com/20210527/2590f702da914f35a682a999cbfbae7d.jpg)
![](https://image.cha138.com/20210527/8701ee4b4c55469e94c8aa13debe3c78.jpg)
5、代码实际测试
-
5.1 获取json字符串
- 这里json字符串存储在文件中
![](https://image.cha138.com/20210527/266e02fa92c84e148c9e14aff2ca943c.jpg)
-
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 实际效果
![](https://image.cha138.com/20210527/bff7214f18914d5590b62fa696cf3199.jpg)
以上是关于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 中正确提取数据