MJExtension
===
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
![podversion](https://img.shields.io/cocoapods/v/MJExtension.svg)
- A fast, convenient and nonintrusive conversion framework between JSON and model.
- 转换速度快、使用简单方便的字典转模型框架
[📜✍🏻**Release Notes**: more details](https://github.com/CoderMJLee/MJExtension/releases)
### ‼️ 纯Swift版的JSON与Model转换框架已经开源上架 ‼️
- [KakaJSON](https://github.com/kakaopensource/KakaJSON)
- [中文教程](https://www.cnblogs.com/mjios/p/11352776.html)
- 如果你的项目是用Swift写的Model,墙裂推荐使用[KakaJSON](https://github.com/kakaopensource/KakaJSON)
- 已经对各种常用的数据场景进行了大量的单元测试
- 简单易用、功能丰富、转换快速
### 关于在Swift中使用MJExtension ‼️
#### ‼️ `@objc` attributes should be added to class and property for declaration of Objc accessibility [在 Swift4 之后, 请在属性前加 `@objc` 修饰. 以保证 Swift 的属性能够暴露给 Objc 使用. ]‼️
#### ‼️ Use `NSNumber` instead of `Bool`, which is not bridged to `BOOL`. [请勿使用 `Bool` 类型, 因为在 Swift 中并没有桥接该类型, 不能显式的对应 `BOOL`, 请使用 `NSNumber` 替代] ‼️
## Contents
* [Getting Started 【开始使用】](#Getting_Started)
* [Features 【能做什么】](#Features)
* [Installation 【安装】](#Installation)
* [Examples 【示例】](#Examples)
* [JSON -> Model](#JSON_Model)
* [JSONString -> Model](#JSONString_Model)
* [Model contains model](#Model_contains_model)
* [Model contains model-array](#Model_contains_model_array)
* [Model name - JSON key mapping](#Model_name_JSON_key_mapping)
* [JSON array -> model array](#JSON_array_model_array)
* [Model -> JSON](#Model_JSON)
* [Model array -> JSON array](#Model_array_JSON_array)
* [Core Data](#Core_Data)
* [Coding](#Coding)
* [Camel -> underline](#Camel_underline)
* [NSString -> NSDate, nil -> @""](#NSString_NSDate)
* [NSDate -> NSString](#NSDate_NSString)
* [More use cases](#More_use_cases)
---
# <a id="Getting_Started"></a> Getting Started【开始使用】
## <a id="Features"></a> Features【能做什么】
- MJExtension是一套字典和模型之间互相转换的超轻量级框架
* `JSON` --> `Model`、`Core Data Model`
* `JSONString` --> `Model`、`Core Data Model`
* `Model`、`Core Data Model` --> `JSON`
* `JSON Array` --> `Model Array`、`Core Data Model Array`
* `JSONString` --> `Model Array`、`Core Data Model Array`
* `Model Array`、`Core Data Model Array` --> `JSON Array`
* Coding all properties of a model with only one line of code.
* 只需要一行代码,就能实现模型的所有属性进行Coding(归档和解档)
## <a id="Installation"></a> Installation【安装】
### From CocoaPods【使用CocoaPods】
```ruby
pod 'MJExtension'
```
### Manually【手动导入】
- Drag all source files under folder `MJExtension` to your project.【将`MJExtension`文件夹中的所有源代码拽入项目中】
- Import the main header file:`#import "MJExtension.h"`【导入主头文件:`#import "MJExtension.h"`】
```objc
MJExtension.h
MJConst.h MJConst.m
MJFoundation.h MJFoundation.m
MJProperty.h MJProperty.m
MJType.h MJType.m
NSObject+MJCoding.h NSObject+MJCoding.m
NSObject+MJProperty.h NSObject+MJProperty.m
NSObject+MJKeyValue.h NSObject+MJKeyValue.m
```
# <a id="Examples"></a> Examples【示例】
**Add `MJKeyValue` protocol to your model if needed【如果有需要, 请在模型中加入 `MJKeyValue` 协议】**
### <a id="JSON_Model"></a> The most simple JSON -> Model【最简单的字典转模型】
```objc
typedef enum {
SexMale,
SexFemale
} Sex;
@interface User : NSObject
@property (copy, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *icon;
@property (assign, nonatomic) unsigned int age;
@property (copy, nonatomic) NSString *height;
@property (strong, nonatomic) NSNumber *money;
@property (assign, nonatomic) Sex sex;
@property (assign, nonatomic, getter=isGay) BOOL gay;
@end
/***********************************************/
NSDictionary *dict = @{
@"name" : @"Jack",
@"icon" : @"lufy.png",
@"age" : @20,
@"height" : @"1.55",
@"money" : @100.9,
@"sex" : @(SexFemale),
@"gay" : @"true"
// @"gay" : @"1"
// @"gay" : @"NO"
};
// JSON -> User
User *user = [User mj_objectWithKeyValues:dict];
NSLog(@"name=%@, icon=%@, age=%zd, height=%@, money=%@, sex=%d, gay=%d", user.name, user.icon, user.age, user.height, user.money, user.sex, user.gay);
// name=Jack, icon=lufy.png, age=20, height=1.550000, money=100.9, sex=1
```
### <a id="JSONString_Model"></a> JSONString -> Model【JSON字符串转模型】
```objc
// 1.Define a JSONString
NSString *jsonString = @"{\"name\":\"Jack\", \"icon\":\"lufy.png\", \"age\":20}";
// 2.JSONString -> User
User *user = [User mj_objectWithKeyValues:jsonString];
// 3.Print user's properties
NSLog(@"name=%@, icon=%@, age=%d", user.name, user.icon, user.age);
// name=Jack, icon=lufy.png, age=20
```
### <a id="Model_contains_model"></a> Model contains model【模型中嵌套模型】
```objc
@interface Status : NSObject
@property (copy, nonatomic) NSString *text;
@property (strong, nonatomic) User *user;
@property (strong, nonatomic) Status *retweetedStatus;
@end
/***********************************************/
NSDictionary *dict = @{
@"text" : @"Agree!Nice weather!",
@"user" : @{
@"name" : @"Jack",
@"icon" : @"lufy.png"
},
@"retweetedStatus" : @{
@"text" : @"Nice weather!",
@"user" : @{
@"name" : @"Rose",
@"icon" : @"nami.png"
}
}
};
// JSON -> Status
Status *status = [Status mj_objectWithKeyValues:dict];
NSString *text = status.text;
NSString *name = status.user.name;
NSString *icon = status.user.icon;
NSLog(@"text=%@, name=%@, icon=%@", text, name, icon);
// text=Agree!Nice weather!, name=Jack, icon=lufy.png
NSString *text2 = status.retweetedStatus.text;
NSString *name2 = status.retweetedStatus.user.name;
NSString *icon2 = status.retweetedStatus.user.icon;
NSLog(@"text2=%@, name2=%@, icon2=%@", text2, name2, icon2);
// text2=Nice weather!, name2=Rose, icon2=nami.png
```
### <a id="Model_contains_model_array"></a> Model contains model-array【模型中有个数组属性,数组里面又要装着其他模型】
```objc
@interface Ad : NSObject
@property (copy, nonatomic) NSString *image;
@property (copy, nonatomic) NSString *url;
@end
@interface StatusResult : NSObject
/** Contatins status model */
@property (strong, nonatomic) NSMutableArray *statuses;
/** Contatins ad model */
@property (strong, nonatomic) NSArray *ads;
@property (strong, nonatomic) NSNumber *totalNumber;
@end
/***********************************************/
// Tell MJExtension what type of model will be contained in statuses and ads.
[StatusResult mj_setupObjectClassInArray:^NSDictionary *{
return @{
@"statuses" : @"Status",
// @"statuses" : [Status class],
@"ads" : @"Ad"
// @"ads" : [Ad class]
};
}];
// Equals: StatusResult.m implements +mj_objectClassInArray method.
NSDictionary *dict = @{
@"statuses" : @[
@{
@"text" : @"Nice weather!",
@"user" : @{
@"name" : @"Rose",
@"icon" : @"nami.png"
}
},
@{
@"text" : @"Go camping tomorrow!",
@"user" : @{
@"name" : @"Jack",
@"icon" : @"lufy.png"
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
iOS安全之【拦截请求,实现特定目的 】(修改HTTPHeaderField、不走全局proxy、设置代理IP和端口、对网络请求...
共516个文件
h:132个
m:47个
sample:13个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 6 下载量 162 浏览量
2021-04-20
11:01:02
上传
评论 2
收藏 720KB ZIP 举报
温馨提示
1、文章:https://kunnan.blog.csdn.net/article/details/115690756 2、应用场景: 2.1、 自定义请求头的HTTPHeaderField 2.2、针对NSURLSessionConfiguration设置代理IP和端口,让一些特殊的请求走自定义的隧道IP和端口 2.3、对网络请求的数据进行报文级别的加密:使用NSURLProtocol来自动监听HTTP请求并加密解密。 通过[NSURLProtocol registerClass: [NetworkInject class]];注入了自定义的NSURLProtocol类 3、原理:利用NSURLProtocol 拦截 HTTP 请求
资源推荐
资源详情
资源评论
收起资源包目录
iOS安全之【拦截请求,实现特定目的 】(修改HTTPHeaderField、不走全局proxy、设置代理IP和端口、对网络请求的数据进行报文级别的加密) (516个子文件)
001b1a105f93edcfb95c076e49ac578eb1e427 103B
0105920538baf032de28a533d19f13c91eb206 63B
02077f452c2afb9a40231d82e1f4d21208227a 13KB
02a405222e427fbcbc7c607937a435db5103ed 1KB
041b67910c17783e7f6c857f33add462a84a7a 51B
04b3c9cdcf5e899de72a4256f1edef311a8587 339B
058af9133c07b4be72450d84f445efb3e75883 70B
06a711b9a9fcf65f2769311d277d344a2feb9e 148B
075b69468a27cffd9177a01ec8336da11b40c4 162B
08fa5bfe4cfdd517a65e339e4e8c63f7543925 954B
093032278713149a5048d5330c689763968555 32B
0935729351719d10d001c3d25659ee9c957b40 2KB
09428bdc03bcd57cc7d0bcfd69829e1d40743f 117B
0c8fcacbf2cfd4a7292dfe7a74d278e103b7f9 821B
0d59bb852fa191fbda44ee9f3d9f9bed1fb93d 658B
0f87f4ccbc518120440fe6ae6bc1aa1885f535 81B
0fd960827d384dbc1f979e4ee10ad76ce30231 811B
1031ea6e53e80dd129234562461596146e5a78 160B
121a68a317fc45a112d0ab7ae2e093b65c53c2 285B
12a5dc4ff9d7b97050d263e88db8a6941eb4c9 59B
12d7cde1d181ffa6a8314de884c4ff36aab6d6 1KB
14658c58c249808f6e9d58db336fe42c63548a 373B
1492abbc7365df3db945abe3c3dad8967de621 2KB
168355fe51c16db657fe48a42bc4732972dcb0 1KB
17b69a45160f757083e6309b8aed406ed9eab7 94B
17e552efec79179e83afe4c2adb58fdeea95ca 2KB
18234bbe6c127b08d74ae8b9c157d23ad6bb40 480B
183ae51d5a9814cf2ce09df1755e933e5dfe6b 682B
18a5abb5bf766eb009916fe7fa6f4ec7d47756 119B
18b43b984a7b5a21b4ae149bdf87ed658f5d30 1KB
19a942b7bb25f3259f7466c831c5c8a641882f 990B
1c25d1c6ecfb16be58c055114a40aa05eba60b 556B
1c552d9b07f2a886b438bdb166c8b31ef7d8a2 3KB
1d0ea716521316977ee96dc3f86156043a123c 52B
1d8cda6861fc0752ff1366b18d7bd50cbfb669 1KB
1e468515060589d0db8d53b651632ac0214d8c 63B
203c0b470c44f628020108be909d92f6921b82 140B
217e225fa4130e848c43dac5695cefb32a0df6 378B
21b9bb1a35f5de270a41afa01305478221ae32 253B
264560ed446aeb891cebf0ab83ecad45abf977 2KB
282ee15f3b03b7483c51ccc0c4bd637942f402 876B
286576e7e7a1133cb4cd6b0af19d9fc79c861e 6KB
294c6ca577e88d104a902adb8f68e8052fb0f4 677B
2c4194cee3a257c59e304132c4b8b4322f7764 48B
2fba07a537a28159e21bc1d83f56f24d936cdc 51B
316ca21c2dd99f4394830d0cf7626282399ddf 566B
317df5ee1bf7722ff40a57f3959cedc233e9d3 745B
319e94b64fb0e5b0d2a91c21187b9b65506522 1KB
320e3fc2d99c31fe9dcfb41b508b900674a602 59B
327ddc8eae21bcec110535b8d80a6a3a725ea2 599B
343d266af8d28707b76eec4151514a6d62a8ae 1KB
37330f78bcda317a528ef9863a3796bc3a4c91 1KB
390d15a54aae49383baa1bb881343ecbbab50a 573B
3a4b50776752f5c90632f329e10420a8787524 731B
3b0c2c1b7238d91a9476388f5a0bbe20c6b004 153B
3cc9b8ba4e4ae5c6df5ed5e3f199668b7fead0 68B
3ce69e815730fa759cdbf7f94bc5fe077e649e 47B
3eb62337d022d2709c563283ad963ec815d214 52B
3eec167b3f410be2109699c7fd0eb7e2114aab 3KB
3f559c8c0d77d96ea662c14ee0d1b6b22995cc 181B
408858750883591b0caf4941f6be5e3a7289c4 336B
40b303768c5a96977da4d3e9544e29e786bfef 47B
43730a5cc25b1c910fa2df43f229aee5eba359 157B
43c00c260d8ce378dec6b57fd0e766233ce646 665B
4736977e3ae5c1124a00552f81c7d5815df4de 383B
4748d8ea2a96134dea32533b0a686b559fec6d 6KB
4c6f166e0d1f85a3fe72e14c81a1f0767f46cf 298B
4cdc8405b006d4343c96c91aea8f2b04050c32 57B
4e3d277c368175d7b3be79577a3b59958d5350 122B
4f799f5ee413f60181a3230db5ab6f1cf58f04 53B
5139fac520a13bec9f705f132ca512f5fc1117 337B
52ff8f84035ea964c1be1f763f57fd0b57312f 2KB
533c5c71d47207ce69eb1562f1db4198e2a763 953B
539a214948eefa610897128b06b5be0cf2b487 1KB
53ca774e6582333e604623c6a905692484b5df 2KB
53f27aa3c6efa64cf7c55dbfa3edb9aa428f77 582B
54d830948bb943d54552219b272c41696e26d2 2KB
5600162a9b7de6e675cdf555a75094d2db490f 120B
561cef48e5ac4e36eaf51f289d2daa6285eec0 68B
59f6a857612454fa2b2ad7f4fe4ddc0e700594 378B
5b17d91d056ce8c7318372f687d80ba614c394 55B
5d45231a0693b0f64199c6af4c0e760911b1c5 519B
5e9329f3767a7c1dd66294b8025bf81dee7d2c 781B
60451a3c2fd7d706b50f07b7b80f49f9c35d74 49B
60a89ae85cc6c2f0bab8b9bb98e16a42e8f1a7 57B
61eff6b1f706c2bbe644cda315bcaf166e8028 44B
62cbd2e31f5cb8317e6cf0ec794af966f151ff 345B
63f856a47de01c8740c734fc050b77e2ac4c6f 145B
65332110ab223166ee7148d12f7b26788c3e11 390B
653bdd4409157170a33fd72f61804562f812d8 175B
65d851489226e859e26ce084d3f4bc0393a0a2 939B
66913a0988ff09857266eab26ecbf6411e7e77 142B
66d2f78f84dbcf8b20d0504b7323ea0f12ae24 45B
66d59e2752ea30875a7eedd38184ff322f695d 182B
69e312a16aa8a1d6fcc37c35447f76e9c93cf4 719B
69edc538e410b4d99bc87eb76ef11963e7c77b 61B
6a508cac94ef012995eff8fed262dfac3bc062 186B
6bd324c26d854187559f27f8194c8afd1795ac 58B
6d4fe5190d3907bae4351c1e12dd4601a9d103 903B
6d93d6c731629a71b1bb5a723e608aa10dcc62 1KB
共 516 条
- 1
- 2
- 3
- 4
- 5
- 6
iOS逆向
- 粉丝: 5293
- 资源: 104
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页