热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

神剑若水哥:JSONExport工具

JSONExport工具JSONExport是把JSONExport的格式文件转换成为Model对象的工具。下面是JSONExportgi
JSONExport 工具

JSONExport 是把JSONExport 的格式文件转换成为Model 对象的工具。

下面是JSONExport gitHub地址:

一.安装方法:

1.下载代码

神剑若水哥:JSONExport 工具
image-20191008110408108

2.用XCode打开工程

神剑若水哥:JSONExport 工具
image-20191008110529415

3.编译工程:Command+B

神剑若水哥:JSONExport 工具
image-20191008110713609

4.找到软件包:product 文件夹下的包文件,右键,Show in Finder

神剑若水哥:JSONExport 工具
image-20191008110856285

5.拖入应用程序

神剑若水哥:JSONExport 工具
image-20191008111128652
二.使用:

1.解析,将下面的json 文字复制到json data 如图

{ "name":"李四", "age":20, "cars":["宝马车","路虎车","保时捷"], "cer":{"Compuer":"l1","Enlish":"4"}, "address":"河南" }

神剑若水哥:JSONExport 工具
image-20191008123239793

说明:

1.Person 是RootClass 的名字,
2.FZ 是所有类的前缀,
3.FZBaseModel是所有类的父亲(或者叫基类吧)。
4.是选择开发语言

2.构造方法 Constructor

注意:选中Constructor的时候,会有构造方法,没选中没有构造方法。

2.1选中Constructor:

代码如下:

.h代码:

#import #import "FZBaseModel.h" #import "FZCer.h" @interface FZPerson : FZBaseModel @property (nonatomic, strong) NSString * address; @property (nonatomic, assign) NSInteger age; @property (nonatomic, strong) NSArray * cars; @property (nonatomic, strong) FZCer * cer; @property (nonatomic, strong) NSString * name; -(instancetype)initWithDictionary:(NSDictionary *)dictionary; @end

.m 代码

// // FZPerson.m // Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport #import "FZPerson.h" NSString *const kFZPersOnAddress= @"address"; NSString *const kFZPersOnAge= @"age"; NSString *const kFZPersOnCars= @"cars"; NSString *const kFZPersOnCer= @"cer"; NSString *const kFZPersOnName= @"name"; @interface FZPerson () @end @implementation FZPerson /** * Instantiate the instance using the passed dictionary values to set the properties values */ -(instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if(![dictionary[kFZPersonAddress] isKindOfClass:[NSNull class]]){ self.address = dictionary[kFZPersonAddress]; } if(![dictionary[kFZPersonAge] isKindOfClass:[NSNull class]]){ self.age = [dictionary[kFZPersonAge] integerValue]; } if(![dictionary[kFZPersonCars] isKindOfClass:[NSNull class]]){ self.cars = dictionary[kFZPersonCars]; } if(![dictionary[kFZPersonCer] isKindOfClass:[NSNull class]]){ self.cer = [[FZCer alloc] initWithDictionary:dictionary[kFZPersonCer]]; } if(![dictionary[kFZPersonName] isKindOfClass:[NSNull class]]){ self.name = dictionary[kFZPersonName]; } return self; } @end

3.实用方法方法 Utility methods

选中会有如下三个方法,如果没选中,就没有这四个方法

-(NSDictionary *)toDictionary; - (void)initWithCoder:(NSCoder *)aCoder; - (void)encodeWithCoder:(NSCoder *)aCoder - (instancetype)copyWithZone:(NSZone *)zone

1.toDictionary model 转化为字典。

2.initWithCoder model 归档方法

3.encodeWithCoder model 解归档方法

4.copyWithZone model在 copy 的时候使用

神剑若水哥:JSONExport 工具
image-20191008115829983

代码如下:

.h代码

#import #import "FZBaseModel.h" #import "FZCer.h" @interface FZPerson : FZBaseModel @property (nonatomic, strong) NSString * address; @property (nonatomic, assign) NSInteger age; @property (nonatomic, strong) NSArray * cars; @property (nonatomic, strong) FZCer * cer; @property (nonatomic, strong) NSString * name; -(NSDictionary *)toDictionary; @end

.m代码

// // FZPerson.m // Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport #import "FZPerson.h" NSString *const kFZPersOnAddress= @"address"; NSString *const kFZPersOnAge= @"age"; NSString *const kFZPersOnCars= @"cars"; NSString *const kFZPersOnCer= @"cer"; NSString *const kFZPersOnName= @"name"; @interface FZPerson () @end @implementation FZPerson /** * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property */ -(NSDictionary *)toDictionary { NSMutableDictionary * dictiOnary= [NSMutableDictionary dictionary]; if(self.address != nil){ dictionary[kFZPersonAddress] = self.address; } dictionary[kFZPersonAge] = @(self.age); if(self.cars != nil){ dictionary[kFZPersonCars] = self.cars; } if(self.cer != nil){ dictionary[kFZPersonCer] = [self.cer toDictionary]; } if(self.name != nil){ dictionary[kFZPersonName] = self.name; } return dictionary; } /** * Implementation of NSCoding encoding method */ /** * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property */ - (void)encodeWithCoder:(NSCoder *)aCoder { if(self.address != nil){ [aCoder encodeObject:self.address forKey:kFZPersonAddress]; } [aCoder encodeObject:@(self.age) forKey:kFZPersonAge]; if(self.cars != nil){ [aCoder encodeObject:self.cars forKey:kFZPersonCars]; } if(self.cer != nil){ [aCoder encodeObject:self.cer forKey:kFZPersonCer]; } if(self.name != nil){ [aCoder encodeObject:self.name forKey:kFZPersonName]; } } /** * Implementation of NSCoding initWithCoder: method */ - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super init]; self.address = [aDecoder decodeObjectForKey:kFZPersonAddress]; self.age = [[aDecoder decodeObjectForKey:kFZPersonAge] integerValue]; self.cars = [aDecoder decodeObjectForKey:kFZPersonCars]; self.cer = [aDecoder decodeObjectForKey:kFZPersonCer]; self.name = [aDecoder decodeObjectForKey:kFZPersonName]; return self; } /** * Implementation of NSCopying copyWithZone: method */ - (instancetype)copyWithZone:(NSZone *)zone { FZPerson *copy = [FZPerson new]; copy.address = [self.address copy]; copy.age = self.age; copy.cars = [self.cars copy]; copy.cer = [self.cer copy]; copy.name = [self.name copy]; return copy; } @end

4.保存

神剑若水哥:JSONExport 工具
image-20191008120107264

总结,我自己使用的时候一搬是结合YYModel 使用,所以不需要生成一些构造和辅助方法。一般不选中。


推荐阅读
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • 本文介绍了在MFC下利用C++和MFC的特性动态创建窗口的方法,包括继承现有的MFC类并加以改造、插入工具栏和状态栏对象的声明等。同时还提到了窗口销毁的处理方法。本文详细介绍了实现方法并给出了相关注意事项。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 电话号码的字母组合解题思路和代码示例
    本文介绍了力扣题目《电话号码的字母组合》的解题思路和代码示例。通过使用哈希表和递归求解的方法,可以将给定的电话号码转换为对应的字母组合。详细的解题思路和代码示例可以帮助读者更好地理解和实现该题目。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • C# 7.0 新特性:基于Tuple的“多”返回值方法
    本文介绍了C# 7.0中基于Tuple的“多”返回值方法的使用。通过对C# 6.0及更早版本的做法进行回顾,提出了问题:如何使一个方法可返回多个返回值。然后详细介绍了C# 7.0中使用Tuple的写法,并给出了示例代码。最后,总结了该新特性的优点。 ... [详细]
  • 本文介绍了Java高并发程序设计中线程安全的概念与synchronized关键字的使用。通过一个计数器的例子,演示了多线程同时对变量进行累加操作时可能出现的问题。最终值会小于预期的原因是因为两个线程同时对变量进行写入时,其中一个线程的结果会覆盖另一个线程的结果。为了解决这个问题,可以使用synchronized关键字来保证线程安全。 ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • 本文讨论了微软的STL容器类是否线程安全。根据MSDN的回答,STL容器类包括vector、deque、list、queue、stack、priority_queue、valarray、map、hash_map、multimap、hash_multimap、set、hash_set、multiset、hash_multiset、basic_string和bitset。对于单个对象来说,多个线程同时读取是安全的。但如果一个线程正在写入一个对象,那么所有的读写操作都需要进行同步。 ... [详细]
author-avatar
Bboy龙超
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有