{"id":1724,"url":"https://github.com/CoderMJLee/MJExtension","last_synced_at":"2025-08-02T04:32:28.541Z","repository":{"id":17334039,"uuid":"20105255","full_name":"CoderMJLee/MJExtension","owner":"CoderMJLee","description":"A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.","archived":false,"fork":false,"pushed_at":"2024-03-13T05:26:26.000Z","size":2716,"stargazers_count":8515,"open_issues_count":27,"forks_count":2158,"subscribers_count":326,"default_branch":"master","last_synced_at":"2024-10-29T11:16:14.480Z","etag":null,"topics":["array","dictionary","json","model","objective-c"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoderMJLee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-05-23T15:54:00.000Z","updated_at":"2024-10-25T16:14:19.000Z","dependencies_parsed_at":"2024-03-13T04:30:13.231Z","dependency_job_id":"5f516ca5-dc9e-4fd4-87c6-636b3a579471","html_url":"https://github.com/CoderMJLee/MJExtension","commit_stats":{"total_commits":301,"total_committers":33,"mean_commits":9.121212121212121,"dds":"0.42524916943521596","last_synced_commit":"43dce6be9c91a7034d37ed171b3e60a7bb760857"},"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMJLee%2FMJExtension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMJLee%2FMJExtension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMJLee%2FMJExtension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderMJLee%2FMJExtension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderMJLee","download_url":"https://codeload.github.com/CoderMJLee/MJExtension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228439110,"owners_count":17920018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","dictionary","json","model","objective-c"],"created_at":"2024-01-05T20:15:54.308Z","updated_at":"2024-12-06T08:31:32.660Z","avatar_url":"https://github.com/CoderMJLee.png","language":"Objective-C","readme":"MJExtension\n===\n[![SPM supported](https://img.shields.io/badge/SPM-supported-4BC51D.svg?style=flat)](https://github.com/apple/swift-package-manager)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![podversion](https://img.shields.io/cocoapods/v/MJExtension.svg)](https://cocoapods.org/pods/MJExtension)\n![Platform](https://img.shields.io/cocoapods/p/MJExtension.svg?style=flat)\n\n- A fast, convenient and nonintrusive conversion framework between JSON and model.\n- 转换速度快、使用简单方便的字典转模型框架\n\n[📜✍🏻**Release Notes**: more details](https://github.com/CoderMJLee/MJExtension/releases)\n\n## Contents\n\n* [Getting Started 【开始使用】](#Getting_Started)\n\t* [Features 【能做什么】](#Features)\n\t* [Installation 【安装】](#Installation)\n* [Examples 【示例】](#Examples)\n  * [Usage in Swift](#usage_in_swift)\n  * [JSON -\u003e Model](#JSON_Model)\n  * [JSONString -\u003e Model](#JSONString_Model)\n  * [Model contains model](#Model_contains_model)\n  * [Model contains model-array](#Model_contains_model_array)\n  * [Model name - JSON key mapping](#Model_name_JSON_key_mapping)\n  * [JSON array -\u003e model array](#JSON_array_model_array)\n  * [Model -\u003e JSON](#Model_JSON)\n  * [Model array -\u003e JSON array](#Model_array_JSON_array)\n  * [Core Data](#Core_Data)\n  * [Coding](#Coding)\n  * [Secure Coding](#SecureCoding)\n  * [Camel -\u003e underline](#Camel_underline)\n  * [NSString -\u003e NSDate, nil -\u003e @\"\"](#NSString_NSDate)\n  * [NSDate -\u003e NSString](#NSDate_NSString)\n  * [More use cases](#More_use_cases)\n\n---\n\n## \u003ca id=\"Getting_Started\"\u003e\u003c/a\u003e Getting Started【开始使用】\n\n### \u003ca id=\"Features\"\u003e\u003c/a\u003e Features【能做什么】\n- MJExtension是一套字典和模型之间互相转换的超轻量级框架\n* `JSON` --\u003e `Model`、`Core Data Model`\n* `JSONString` --\u003e `Model`、`Core Data Model`\n* `Model`、`Core Data Model` --\u003e `JSON`\n* `JSON Array` --\u003e `Model Array`、`Core Data Model Array`\n* `JSONString` --\u003e `Model Array`、`Core Data Model Array`\n* `Model Array`、`Core Data Model Array` --\u003e `JSON Array`\n* Coding all properties of a model with only one line of code.\n    * 只需要一行代码，就能实现模型的所有属性进行Coding / SecureCoding（归档和解档）\n\n### \u003ca id=\"Installation\"\u003e\u003c/a\u003e Installation【安装】\n\n#### CocoaPods【使用CocoaPods】\n\n```ruby\npod 'MJExtension'\n```\n\n#### Carthage\n\n```ruby\ngithub \"CoderMJLee/MJExtension\"\n```\n\n#### Swift Package Manager\n\nReleased from [`3.4.0`](https://github.com/CoderMJLee/MJExtension/releases/)\n\n#### Manually【手动导入】\n\n- Drag all source files under folder `MJExtension` to your project.【将`MJExtension`文件夹中的所有源代码拽入项目中】\n- Import the main header file：`#import \"MJExtension.h\"`【导入主头文件：`#import \"MJExtension.h\"`】\n\n## \u003ca id=\"Examples\"\u003e\u003c/a\u003e Examples【示例】\n\n**Add `MJKeyValue` protocol to your model if needed【如果有需要, 请在模型中加入 `MJKeyValue` 协议】**\n\n### \u003ca id=\"usage_in_swift\"\u003e\u003c/a\u003e Usage in Swift [关于在Swift中使用MJExtension] ‼️\n\n\u003e Example: \n\u003e\n\u003e - [Model - MJTester.swift](MJExtensionTests/SwiftModel/MJTester.swift)\n\u003e\n\u003e - [Usage - SwiftModelTests.swift](MJExtensionTests/SwiftModelTests.swift)\n\n```swift\n@objc(MJTester)\n@objcMembers\nclass MJTester: NSObject {\n    // make sure to use `dynamic` attribute for basic type \u0026 must use as Non-Optional \u0026 must set initial value\n    dynamic var isSpecialAgent: Bool = false\n    dynamic var age: Int = 0\n    \n    var name: String?\n    var identifier: String?\n}\n```\n\n1.  `@objc` or `@objcMembers` attributes should be added to class or property for declaration of Objc accessibility [在 Swift4 之后, 请在属性前加 `@objc` 修饰或在类前增加 `@objcMembers`. 以保证 Swift 的属性能够暴露给 Objc 使用. ]\n2.  If you let `Bool` \u0026 `Int` as property type, make sure that using `dynamic` to attribute it. It must be `Non-Optional` type and assign `a default value`.[如果要使用 `Bool` 和 `Int` 等 Swfit 专用基本类型, 请使用 `dynamic` 关键字修饰, 类型为 `Non-Optional`, 並且给定初始值.]\n\n\u003e 纯Swift版的JSON与Model转换框架已经开源上架\n\u003e\n\u003e - [KakaJSON](https://github.com/kakaopensource/KakaJSON)\n\u003e - [中文教程](https://www.cnblogs.com/mjios/p/11352776.html)\n\u003e - 如果你的项目是用Swift写的Model，墙裂推荐使用[KakaJSON](https://github.com/kakaopensource/KakaJSON)\n\u003e   - 已经对各种常用的数据场景进行了大量的单元测试\n\u003e   - 简单易用、功能丰富、转换快速\n\n### \u003ca id=\"JSON_Model\"\u003e\u003c/a\u003e The most simple JSON -\u003e Model【最简单的字典转模型】\n\n```objc\ntypedef enum {\n    SexMale,\n    SexFemale\n} Sex;\n\n@interface User : NSObject\n@property (copy, nonatomic) NSString *name;\n@property (copy, nonatomic) NSString *icon;\n@property (assign, nonatomic) unsigned int age;\n@property (copy, nonatomic) NSString *height;\n@property (strong, nonatomic) NSNumber *money;\n@property (assign, nonatomic) Sex sex;\n@property (assign, nonatomic, getter=isGay) BOOL gay;\n@end\n\n/***********************************************/\n\nNSDictionary *dict = @{\n    @\"name\" : @\"Jack\",\n    @\"icon\" : @\"lufy.png\",\n    @\"age\" : @20,\n    @\"height\" : @\"1.55\",\n    @\"money\" : @100.9,\n    @\"sex\" : @(SexFemale),\n    @\"gay\" : @\"true\"\n//   @\"gay\" : @\"1\"\n//   @\"gay\" : @\"NO\"\n};\n\n// JSON -\u003e User\nUser *user = [User mj_objectWithKeyValues:dict];\n\nNSLog(@\"name=%@, icon=%@, age=%zd, height=%@, money=%@, sex=%d, gay=%d\", user.name, user.icon, user.age, user.height, user.money, user.sex, user.gay);\n// name=Jack, icon=lufy.png, age=20, height=1.550000, money=100.9, sex=1\n```\n\n### \u003ca id=\"JSONString_Model\"\u003e\u003c/a\u003e JSONString -\u003e Model【JSON字符串转模型】\n\n```objc\n// 1.Define a JSONString\nNSString *jsonString = @\"{\\\"name\\\":\\\"Jack\\\", \\\"icon\\\":\\\"lufy.png\\\", \\\"age\\\":20}\";\n\n// 2.JSONString -\u003e User\nUser *user = [User mj_objectWithKeyValues:jsonString];\n\n// 3.Print user's properties\nNSLog(@\"name=%@, icon=%@, age=%d\", user.name, user.icon, user.age);\n// name=Jack, icon=lufy.png, age=20\n```\n\n### \u003ca id=\"Model_contains_model\"\u003e\u003c/a\u003e Model contains model【模型中嵌套模型】\n\n```objc\n@interface Status : NSObject\n@property (copy, nonatomic) NSString *text;\n@property (strong, nonatomic) User *user;\n@property (strong, nonatomic) Status *retweetedStatus;\n@end\n\n/***********************************************/\n\nNSDictionary *dict = @{\n    @\"text\" : @\"Agree!Nice weather!\",\n    @\"user\" : @{\n        @\"name\" : @\"Jack\",\n        @\"icon\" : @\"lufy.png\"\n    },\n    @\"retweetedStatus\" : @{\n        @\"text\" : @\"Nice weather!\",\n        @\"user\" : @{\n            @\"name\" : @\"Rose\",\n            @\"icon\" : @\"nami.png\"\n        }\n    }\n};\n\n// JSON -\u003e Status\nStatus *status = [Status mj_objectWithKeyValues:dict];\n\nNSString *text = status.text;\nNSString *name = status.user.name;\nNSString *icon = status.user.icon;\nNSLog(@\"text=%@, name=%@, icon=%@\", text, name, icon);\n// text=Agree!Nice weather!, name=Jack, icon=lufy.png\n\nNSString *text2 = status.retweetedStatus.text;\nNSString *name2 = status.retweetedStatus.user.name;\nNSString *icon2 = status.retweetedStatus.user.icon;\nNSLog(@\"text2=%@, name2=%@, icon2=%@\", text2, name2, icon2);\n// text2=Nice weather!, name2=Rose, icon2=nami.png\n```\n\n### \u003ca id=\"Model_contains_model_array\"\u003e\u003c/a\u003e Model contains model-array【模型中有个数组属性，数组里面又要装着其他模型】\n\n```objc\n@interface Ad : NSObject\n@property (copy, nonatomic) NSString *image;\n@property (copy, nonatomic) NSString *url;\n@end\n\n@interface StatusResult : NSObject\n/** Contatins status model */\n@property (strong, nonatomic) NSMutableArray *statuses;\n/** Contatins ad model */\n@property (strong, nonatomic) NSArray *ads;\n@property (strong, nonatomic) NSNumber *totalNumber;\n@end\n\n/***********************************************/\n\n// Tell MJExtension what type of model will be contained in statuses and ads.\n[StatusResult mj_setupObjectClassInArray:^NSDictionary *{\n    return @{\n               @\"statuses\" : @\"Status\",\n               // @\"statuses\" : [Status class],\n               @\"ads\" : @\"Ad\"\n               // @\"ads\" : [Ad class]\n           };\n}];\n// Equals: StatusResult.m implements +mj_objectClassInArray method.\n\nNSDictionary *dict = @{\n    @\"statuses\" : @[\n                      @{\n                          @\"text\" : @\"Nice weather!\",\n                          @\"user\" : @{\n                              @\"name\" : @\"Rose\",\n                              @\"icon\" : @\"nami.png\"\n                          }\n                      },\n                      @{\n                          @\"text\" : @\"Go camping tomorrow!\",\n                          @\"user\" : @{\n                              @\"name\" : @\"Jack\",\n                              @\"icon\" : @\"lufy.png\"\n                          }\n                      }\n                  ],\n    @\"ads\" : @[\n                 @{\n                     @\"image\" : @\"ad01.png\",\n                     @\"url\" : @\"http://www.ad01.com\"\n                 },\n                 @{\n                     @\"image\" : @\"ad02.png\",\n                     @\"url\" : @\"http://www.ad02.com\"\n                 }\n             ],\n    @\"totalNumber\" : @\"2014\"\n};\n\n// JSON -\u003e StatusResult\nStatusResult *result = [StatusResult mj_objectWithKeyValues:dict];\n\nNSLog(@\"totalNumber=%@\", result.totalNumber);\n// totalNumber=2014\n\n// Printing\nfor (Status *status in result.statuses) {\n    NSString *text = status.text;\n    NSString *name = status.user.name;\n    NSString *icon = status.user.icon;\n    NSLog(@\"text=%@, name=%@, icon=%@\", text, name, icon);\n}\n// text=Nice weather!, name=Rose, icon=nami.png\n// text=Go camping tomorrow!, name=Jack, icon=lufy.png\n\n// Printing\nfor (Ad *ad in result.ads) {\n    NSLog(@\"image=%@, url=%@\", ad.image, ad.url);\n}\n// image=ad01.png, url=http://www.ad01.com\n// image=ad02.png, url=http://www.ad02.com\n```\n\n### \u003ca id=\"Model_name_JSON_key_mapping\"\u003e\u003c/a\u003e Model name - JSON key mapping【模型中的属性名和字典中的key不相同(或者需要多级映射)】\n\n```objc\n@interface Bag : NSObject\n@property (copy, nonatomic) NSString *name;\n@property (assign, nonatomic) double price;\n@end\n\n@interface Student : NSObject\n@property (copy, nonatomic) NSString *ID;\n@property (copy, nonatomic) NSString *desc;\n@property (copy, nonatomic) NSString *nowName;\n@property (copy, nonatomic) NSString *oldName;\n@property (copy, nonatomic) NSString *nameChangedTime;\n@property (strong, nonatomic) Bag *bag;\n@end\n\n/***********************************************/\n\n// How to map\n[Student mj_setupReplacedKeyFromPropertyName:^NSDictionary *{\n    return @{\n               @\"ID\" : @\"id\",\n               @\"desc\" : @\"description\",\n               @\"oldName\" : @\"name.oldName\",\n               @\"nowName\" : @\"name.newName\",\n               @\"nameChangedTime\" : @\"name.info[1].nameChangedTime\",\n               @\"bag\" : @\"other.bag\"\n           };\n}];\n// Equals: Student.m implements +mj_replacedKeyFromPropertyName method.\n\nNSDictionary *dict = @{\n    @\"id\" : @\"20\",\n    @\"description\" : @\"kids\",\n    @\"name\" : @{\n        @\"newName\" : @\"lufy\",\n        @\"oldName\" : @\"kitty\",\n        @\"info\" : @[\n        \t\t @\"test-data\",\n        \t\t @{\n            \t             @\"nameChangedTime\" : @\"2013-08\"\n                         }\n                  ]\n    },\n    @\"other\" : @{\n        @\"bag\" : @{\n            @\"name\" : @\"a red bag\",\n            @\"price\" : @100.7\n        }\n    }\n};\n\n// JSON -\u003e Student\nStudent *stu = [Student mj_objectWithKeyValues:dict];\n\n// Printing\nNSLog(@\"ID=%@, desc=%@, oldName=%@, nowName=%@, nameChangedTime=%@\",\n      stu.ID, stu.desc, stu.oldName, stu.nowName, stu.nameChangedTime);\n// ID=20, desc=kids, oldName=kitty, nowName=lufy, nameChangedTime=2013-08\nNSLog(@\"bagName=%@, bagPrice=%f\", stu.bag.name, stu.bag.price);\n// bagName=a red bag, bagPrice=100.700000\n```\n\n\n### \u003ca id=\"JSON_array_model_array\"\u003e\u003c/a\u003e JSON array -\u003e model array【将一个字典数组转成模型数组】\n\n```objc\nNSArray *dictArray = @[\n                         @{\n                             @\"name\" : @\"Jack\",\n                             @\"icon\" : @\"lufy.png\"\n                         },\n                         @{\n                             @\"name\" : @\"Rose\",\n                             @\"icon\" : @\"nami.png\"\n                         }\n                     ];\n\n// JSON array -\u003e User array\nNSArray *userArray = [User mj_objectArrayWithKeyValuesArray:dictArray];\n\n// Printing\nfor (User *user in userArray) {\n    NSLog(@\"name=%@, icon=%@\", user.name, user.icon);\n}\n// name=Jack, icon=lufy.png\n// name=Rose, icon=nami.png\n```\n\n### \u003ca id=\"Model_JSON\"\u003e\u003c/a\u003e Model -\u003e JSON【将一个模型转成字典】\n```objc\n// New model\nUser *user = [[User alloc] init];\nuser.name = @\"Jack\";\nuser.icon = @\"lufy.png\";\n\nStatus *status = [[Status alloc] init];\nstatus.user = user;\nstatus.text = @\"Nice mood!\";\n\n// Status -\u003e JSON\nNSDictionary *statusDict = status.mj_keyValues;\nNSLog(@\"%@\", statusDict);\n/*\n {\n text = \"Nice mood!\";\n user =     {\n icon = \"lufy.png\";\n name = Jack;\n };\n }\n */\n\n// More complex situation\nStudent *stu = [[Student alloc] init];\nstu.ID = @\"123\";\nstu.oldName = @\"rose\";\nstu.nowName = @\"jack\";\nstu.desc = @\"handsome\";\nstu.nameChangedTime = @\"2018-09-08\";\n\nBag *bag = [[Bag alloc] init];\nbag.name = @\"a red bag\";\nbag.price = 205;\nstu.bag = bag;\n\nNSDictionary *stuDict = stu.mj_keyValues;\nNSLog(@\"%@\", stuDict);\n/*\n{\n    ID = 123;\n    bag =     {\n        name = \"\\U5c0f\\U4e66\\U5305\";\n        price = 205;\n    };\n    desc = handsome;\n    nameChangedTime = \"2018-09-08\";\n    nowName = jack;\n    oldName = rose;\n}\n */\n```\n\n### \u003ca id=\"Model_array_JSON_array\"\u003e\u003c/a\u003e Model array -\u003e JSON array【将一个模型数组转成字典数组】\n\n```objc\n// New model array\nUser *user1 = [[User alloc] init];\nuser1.name = @\"Jack\";\nuser1.icon = @\"lufy.png\";\n\nUser *user2 = [[User alloc] init];\nuser2.name = @\"Rose\";\nuser2.icon = @\"nami.png\";\n\nNSArray *userArray = @[user1, user2];\n\n// Model array -\u003e JSON array\nNSArray *dictArray = [User mj_keyValuesArrayWithObjectArray:userArray];\nNSLog(@\"%@\", dictArray);\n/*\n (\n {\n icon = \"lufy.png\";\n name = Jack;\n },\n {\n icon = \"nami.png\";\n name = Rose;\n }\n )\n */\n```\n\n### \u003ca id=\"Core_Data\"\u003e\u003c/a\u003e Core Data\n\n```swift\nfunc json2CoreDataObject() {\n    context.performAndWait {\n        let object = MJCoreDataTester.mj_object(withKeyValues: Values.testJSONObject, context: context)\n        // use the object\n    }\n}\n\nfunc coreDataObject2JSON() {\n    context.performAndWait {        \n        let dict = coreDataObject.mj_keyValues()\n        // use dict\n    }\n}\n```\n\n### \u003ca id=\"Coding\"\u003e\u003c/a\u003e Coding (Archive \u0026 Unarchive methods are deprecated in iOS 12)\n\n```objc\n#import \"MJExtension.h\"\n\n@implementation MJBag\n// NSCoding Implementation\nMJCodingImplementation\n@end\n\n/***********************************************/\n\n// what properties not to be coded\n[MJBag mj_setupIgnoredCodingPropertyNames:^NSArray *{\n    return @[@\"name\"];\n}];\n// Equals: MJBag.m implements +mj_ignoredCodingPropertyNames method.\n\n// Create model\nMJBag *bag = [[MJBag alloc] init];\nbag.name = @\"Red bag\";\nbag.price = 200.8;\n\nNSString *file = [NSHomeDirectory() stringByAppendingPathComponent:@\"Desktop/bag.data\"];\n// Encoding by archiving\n[NSKeyedArchiver archiveRootObject:bag toFile:file];\n\n// Decoding by unarchiving\nMJBag *decodedBag = [NSKeyedUnarchiver unarchiveObjectWithFile:file];\nNSLog(@\"name=%@, price=%f\", decodedBag.name, decodedBag.price);\n// name=(null), price=200.800000\n```\n\n### \u003ca id=\"SecureCoding\"\u003e\u003c/a\u003e Secure Coding\n\nUsing `MJSecureCodingImplementation(class, isSupport)` macro.\n\n```objc\n@import MJExtension;\n\n// NSSecureCoding Implementation\nMJSecureCodingImplementation(MJBag, YES)\n\n@implementation MJBag\n@end\n\n /***********************************************/\n\n// what properties not to be coded\n[MJBag mj_setupIgnoredCodingPropertyNames:^NSArray *{\n    return @[@\"name\"];\n}];\n// Equals: MJBag.m implements +mj_ignoredCodingPropertyNames method.\n\n// Create model\nMJBag *bag = [[MJBag alloc] init];\nbag.name = @\"Red bag\";\nbag.price = 200.8;\nbag.isBig = YES;\nbag.weight = 200;\n\nNSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@\"bag.data\"];\n\nNSError *error = nil;\n// Encoding by archiving\nNSData *data = [NSKeyedArchiver archivedDataWithRootObject:bag requiringSecureCoding:YES error:\u0026error];\n[data writeToFile:file atomically:true];\n\n// Decoding by unarchiving\nNSData *readData = [NSFileManager.defaultManager contentsAtPath:file];\nerror = nil;\nMJBag *decodedBag = [NSKeyedUnarchiver unarchivedObjectOfClass:MJBag.class fromData:readData error:\u0026error];\nMJExtensionLog(@\"name=%@, price=%f\", decodedBag.name, decodedBag.price);\n```\n\n### \u003ca id=\"Camel_underline\"\u003e\u003c/a\u003e Camel -\u003e underline【统一转换属性名（比如驼峰转下划线）】\n\n```objc\n// Dog\n#import \"MJExtension.h\"\n\n@implementation Dog\n+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName\n{\n    // nickName -\u003e nick_name\n    return [propertyName mj_underlineFromCamel];\n}\n@end\n\n// NSDictionary\nNSDictionary *dict = @{\n                       @\"nick_name\" : @\"旺财\",\n                       @\"sale_price\" : @\"10.5\",\n                       @\"run_speed\" : @\"100.9\"\n                       };\n// NSDictionary -\u003e Dog\nDog *dog = [Dog mj_objectWithKeyValues:dict];\n\n// printing\nNSLog(@\"nickName=%@, scalePrice=%f runSpeed=%f\", dog.nickName, dog.salePrice, dog.runSpeed);\n```\n\n### \u003ca id=\"NSString_NSDate\"\u003e\u003c/a\u003e NSString -\u003e NSDate, nil -\u003e @\"\"【过滤字典的值（比如字符串日期处理为NSDate、字符串nil处理为@\"\"）】\n```objc\n// Book\n#import \"MJExtension.h\"\n\n@implementation Book\n- (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property\n{\n    if ([property.name isEqualToString:@\"publisher\"]) {\n        if (oldValue == nil) return @\"\";\n    } else if (property.type.typeClass == [NSDate class]) {\n        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];\n        fmt.dateFormat = @\"yyyy-MM-dd\";\n        return [fmt dateFromString:oldValue];\n    }\n\n    return oldValue;\n}\n@end\n\n// NSDictionary\nNSDictionary *dict = @{\n                       @\"name\" : @\"5分钟突破iOS开发\",\n                       @\"publishedTime\" : @\"2011-09-10\"\n                       };\n// NSDictionary -\u003e Book\nBook *book = [Book mj_objectWithKeyValues:dict];\n\n// printing\nNSLog(@\"name=%@, publisher=%@, publishedTime=%@\", book.name, book.publisher, book.publishedTime);\n```\n\n### \u003ca id=\"NSDate_NSString\"\u003e\u003c/a\u003e NSDate -\u003e NSString【模型转字典时, 修改 Date 类型至 String】\n\n```objc\n- (void)mj_objectDidConvertToKeyValues:(NSMutableDictionary *)keyValues {\n    // NSDateFormatter *formatter = [[NSDateFormatter alloc] init];\n    // formatter.dateFormat = @\"yyy-MM-dd\";\n    // should use sharedFormatter for better performance  \n    keyValues[@\"publishedTime\"] = [sharedFormatter stringFromDate:self.publishedTime];\n}\n```\n\n\n\n### \u003ca id=\"More_use_cases\"\u003e\u003c/a\u003e More use cases【更多用法】\n\n- Please reference to `NSObject+MJKeyValue.h` and `NSObject+MJCoding.h`\n\n\n## 期待\n* 如果在使用过程中遇到BUG，希望你能Issues我，谢谢（或者尝试下载最新的框架代码看看BUG修复没有）\n* 如果在使用过程中发现功能不够用，希望你能Issues我，我非常想为这个框架增加更多好用的功能，谢谢\n* 如果你想为MJExtension输出代码，请拼命Pull Requests我\n\n","funding_links":[],"categories":["Parsing","Objective-C","Objective-C  Stars 1000以内排名整理","Database, ORM, Cache","OOM-Leaks-Crash","9. 其他与展望","JSON"],"sub_categories":["JSON","Other free courses","Categories-Extensions","5. 参考材料"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCoderMJLee%2FMJExtension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCoderMJLee%2FMJExtension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCoderMJLee%2FMJExtension/lists"}