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 ...
随机推荐
- 服务发现:Zookeeper vs etcd vs Consul
[编者的话]本文对比了Zookeeper.etcd和Consul三种服务发现工具,探讨了最佳的服务发现解决方案,仅供参考. 如果使用预定义的端口,服务越多,发生冲突的可能性越大,毕竟,不可能有两个服务 ...
- Mac无法找到摄像头问题解决
facetime显示“未检测到摄像头”之类的,重启后可能摄像头有工作正常了,摄像头不稳定 重置 NVRAM后恢复正常,据说机器卡的时候,此法也可以使用. https://support.apple.c ...
- [c#基础]值类型和引用类型的Equals,==的区别
引言 最近一个朋友正在找工作,他说在笔试题中遇到Equals和==有什么区别的题,当时跟他说如果是值类型的,它们没有区别,如果是引用类型的有区别,但string类型除外.为了证实自己的说法,也研究了一 ...
- DOM(十)使用DOM设置单选按钮、复选框、下拉菜单
1.设置单选按钮 单选按钮在表单中即<input type="radio" />它是一组供用户选择的对象,但每次只能选一个.每一个都有checked属性,当一项选择为t ...
- 第四次个人作业——关于微软必应词典android客户端的案例分析
[前言] 第一次搞测评这种东西,如果有什么疏漏,请多多谅解.测评内容如题. 第一部分 调研,评测 评测:(设备:Lenovo A806) 软件的bug,功能评测,黑箱测试 bug等级划分方式 5级分类 ...
- 输入年月,输出月份有几天(分别用了if——else和switch)
首先是switch做的 class Program { static void Main(string[] args) {/* 题目要求:请用户输入年份,输入月份,输出该月的天数. 思路:一年中月份的 ...
- zabbix_监控_进程
一.根据进程名称监控 1.创建Item(只能通过进程名.用户过滤进程) http://www.2cto.com/os/201405/302249.html http://www.ithao1 ...
- Lucene 4.7 --高亮显示
jar lucene-analyzers-common-4.7.0.jar lucene-analyzers-smartcn-4.7.0.jar lucene-core-4.7.0.jar lucen ...
- Java 线程并发策略
1 什么是并发问题. 多个进程或线程同时(或着说在同一段时间内)访问同一资源会产生并发问题. 2 java中synchronized的用法 用法1 public class Test{ public ...
- 【CodeForces 599A】D - 特别水的题4- Patrick and Shopping
Description meter long road between his house and the first shop and a d2 meter long road between h ...