JSONModel - 字符串换转实体类
JSONModel
https://github.com/icanzilb/JSONModel/
一. 获取属性的元数据
const char *attrs = property_getAttributes(property);
propertyAttributes=T@"NSArray<OrderDetail><Optional>",&,N,V_OrderDetails
1. T
T表示普通属性
R表示只读属性
Tc,表示BOOL
2. @"NSArray<OrderDetail><Optional>"
@里面"<"之前是类型
@里面"<"和">"之间是协议
3. V_OrderDetails
V表示变量
后面的OrderDetails表示变量名称
二.获取对象的父类
obj.superclass
[isKindOfClass:class]
Magical Data Modelling Framework for JSONhttps://github.com/icanzilb/JSONModel New: In version 0.12.0 I added experimental support for exporting JSON models to CoreData. 最新消息:在0.12.0版本中,我试验性的支持将 JSON models 转化成 CoreData . Give it a try and let me know, post an issue or just get in touch. Try something like that: 如果你试验过了,有空告知哥一下,哥写开源库也不容易,发一篇博文或者给个链接以表支持: NSError* error = nil; If you like JSONModel and use it can you please: 1) star this repo 2)send me some feedback. Thanks! JSONModel is a library, which allows rapid creation of smart data models. You can use it in your iOS or OSX apps. JSONModel automatically introspects your model classes and the structure of your JSON input and reduces drastically the amount of code you have to write. 如果你喜欢 JSONModel ,那么你可以:1)长期关注这个开源项目,2)你是土豪的话,给哥捐点吧,谢谢. JSONModel 是一个库,他能智能并且快速的创建出数据 model,你可以在你的 iOS 项目或者 OSX 项目上使用它. Adding JSONModel to your project添加 JSONModel 到你的工程中Requirements需要的环境:
Get it as: 1) source files
1. 下载 JSONModel zip包 2. 将 JSONModel 文件夹拷贝到你的工程项目中 3. 将库 SystemConfiguration.framework 添加上 or 2) via Cocoa podsIn your project's Podfile add the JSONModel pod: 使用 Cocoa pods 来安装: pod 'JSONModel' If you want to read more about CocoaPods, have a look at this short tutorial. 如果你不会用 CocoaPods,你可以看看这简单的教程。 Source code documentation源码的文档 The source code includes class docs, which you can build yourself and import into Xcode: 源码本身包含了类的文档,你可以自己编译后导入到你的Xcode中:
1. 如果你还没安装 appledoc ,先安装 appledoc 2. 在Xcode上键入 appledoc 安装文档,在根目录下 3. 重启Xcode Basic usage基本使用 Consider you have a JSON like this: 假设你的 JSON 串像下面这样子: {"id":"10", "country":"Germany", "dialCode": 49, "isInEurope":true}
#import "JSONModel.h" @interface CountryModel : JSONModel @property (assign, nonatomic) int id; There's no need to do anything in the .m file. .m文件中你不需要做其他的事情了.
#import "CountryModel.h" If the validation of the JSON passes you have all the corresponding properties in your model populated from the JSON. JSONModel will also try to convert as much data to the types you expect, in the example above it will: 如果传过来的 JSON 合法,你所定义的所有的属性都会与该 JSON 值相匹配,并且 JSONModel 也会尝试尽可能的转换成你所想要的数据,就像上面的例子:
And the good news is all you had to do is define the properties and their expected types. 所以,你需要做的就是定义出你期望的属性就行了。 Online tutorials在线教程 Official website: http://www.jsonmodel.com Class docs online: http://jsonmodel.com/docs/ Step-by-step tutorials: 傻瓜教程: Examples例子 Automatic name based mapping命名自动匹配
Model cascading (models including other models)model中含有其他的model
Model collectionsmodel中含有其他model的集合
Key mapping键值转回匹配
Global key mapping (applies to all models in your app)设置全局的键值转回匹配
Map automatically under_score case to camelCase将下滑线转换成首字母大写
Optional properties (i.e. can be missing or null)可以为空的属性值
Ignored properties (i.e. JSONModel completely ignores them)忽略某些属性
Make all model properties optional (avoid if possible)让所有的属性都可以有空的属性值
Lazy convert collection items from dictionaries to models将集合元素转换成 model
Using the built-in thin HTTP client使用内置的 HTTP 链接 //add extra headers Export model to NSDictionary or to JSON text将 model 导出为字典或者json字符串 ProductModel* pm = [[ProductModel alloc] initWithString:jsonString error:nil];
以下是本人使用的测试结果 |
JSONModel - 字符串换转实体类的更多相关文章
- silverlight依据json字符串动态创建实体类
1.接收json字符串: //用JsonValue转换json字符串是为了之后获得json字符串的每行数据和每一列的列名 JsonValue jv = JsonValue.Parse(json); ...
- 由json字符串生成C#实体类的工具
json作为互联网上轻量便捷的数据传输格式,越来越受到重视.但在服务器端编程过程中,我们常常希望能通过智能提示来提高编码效率.JSON C# Class Generator 能将json格式所表示的J ...
- JSON C# Class Generator ---由json字符串生成C#实体类的工具(转)
转载地址:http://www.cnblogs.com/finesite/archive/2011/07/31/2122984.html json作为互联网上轻量便捷的数据传输格式,越来越受到重视.但 ...
- JSON C# Class Generator ---由json字符串生成C#实体类的工具
json作为互联网上轻量便捷的数据传输格式,越来越受到重视.但在服务器端编程过程中,我们常常希望能通过智能提示来提高编码效率.JSON C# Class Generator 能将json格式所表示的J ...
- json字符串生成C#实体类的工具
转载:http://www.cnblogs.com/finesite/archive/2011/07/31/2122984.html json作为互联网上轻量便捷的数据传输格式,越来越受到重视.但在服 ...
- JSON字符串转C#实体Class类
在项目开发过程中,经常需要和不同部门或者不同的组员一起协同工作,但对方写的json返回的结果集,我们需要用,那么如何来生成对应的类代码和实体对象呢?于是参考了网上的做法,做一个简单的字符串转实体类的功 ...
- c# json数据解析——将字符串json格式数据转换成对象或实体类
网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xml格式,刚刚遇到一个返回json格式数据的接口,通过例子由易到难总结一下处理过程,希望能帮到和我一样开始不会的朋 ...
- JSon实体类快速生成插件 GsonFormat 1.2.0
写在前头:本插件只适用 android studio和 Intellij IDEA 工具,eclipse 的少年无视我吧!!! 这是一个根据JSONObject格式的字符串,自动生成实体类参数. gi ...
- android开发学习 ------- json数据与实体类之间的相互转换
在网络请求的时候,会返回给我们实体类,我们需要将实体类转化为json字符串,方便处理数据: 有时候也会将json数据转换为实体类. 在Android Studio中,json要互相转换,需要用到gso ...
随机推荐
- Day10
会议讨论 628:今天是冲刺的最后一天了,好紧张好激动,我们组还有好些个功能没实现呢,感觉崩崩哒!还要实现选择不同的专业导入不同的课表呢. 601:在修改教师帐号信息的页面要有当密码格式.用户名格式等 ...
- 问问题_Java一次导出百万条数据生成excel(web操作)
需求:在web页面操作,一次导出百万条数据并生成excel 分析: 1.异步生成Excel,非实时,完成后使用某种方式通知用户 2.生成多个excel文件,并打包成zip文件,因为一个excel容纳不 ...
- 整数划分 (区间DP)
整数划分(四) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近 ...
- Js-字符转换数字
s 字符串转化成数字 的 三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数, ...
- PowerDesigner-导出表到word
1. 在工具栏中选择[Report -->Reports],如下图 2. 点击第二个图标创建一个Report,如下图 该wizard中有三个信息 Report name Report : Rep ...
- Hibernate-清理一级缓存
Session执行一些sql语句把内存中的对象的状态同步到数据库,这个过程被称为session清理. 在默认情况下,Session会在下面的时间点清理缓存. 1 当应用程序调用net.sf.hiber ...
- RBAC(基于角色的访问控制权限)表结构
Rbac 支持两种类,PhpManager(基于文件的) 和 DbManager(基于数据库的) 权限:就是指用户是否可以执行哪些操作 角色:就是上面说的一组操作的集合,角色还可以继承 在Yii2.0 ...
- 【转】mac os x系统上Android开发环境的搭建
由于Google官方已经不提供Adt-Bundle下载了,主推AndroidStudio.可以从这个链接下载http://www.androiddevtools.cn.上面不光有adt-bundle, ...
- BZOJ-2748 音量调节 DP+背包(脑残)
水DP,一开始竟然想错了...水了半天....真可怕 2748: [HAOI2012]音量调节 Time Limit: 3 Sec Memory Limit: 128 MB Submit: 1156 ...
- HDU2222 Keywords Search [AC自动机模板]
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...