All Projects → netyouli → Whc_model

netyouli / Whc_model

Licence: mit
iOS平台高效转换引擎json->model,model->json,model->Dictionary,支持模型类继承其他模型类,支持指定路径转换,不区分json的key和模型属性名称大小写,自动处理json中null

Projects that are alternatives of or similar to Whc model

Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (+108.2%)
Mutual labels:  json, json-parser, model
Ladybug
A powerful model framework for Swift 4
Stars: ✭ 147 (-39.75%)
Mutual labels:  json, model
Daw json link
Static JSON parsing in C++
Stars: ✭ 146 (-40.16%)
Mutual labels:  json, json-parser
Json To Ast
JSON AST parser
Stars: ✭ 161 (-34.02%)
Mutual labels:  json, json-parser
Moyamapper
快速解析模型工具,支持RxSwift。同时支持缓存功能 【相关手册 https://MoyaMapper.github.io 】
Stars: ✭ 115 (-52.87%)
Mutual labels:  json, model
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-44.26%)
Mutual labels:  json, model
Helios
A purely functional JSON library for Kotlin built on Λrrow
Stars: ✭ 157 (-35.66%)
Mutual labels:  json, json-parser
Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+436.07%)
Mutual labels:  json, json-parser
Jsons
🐍 A Python lib for (de)serializing Python objects to/from JSON
Stars: ✭ 178 (-27.05%)
Mutual labels:  json, json-parser
Simdjson
Parsing gigabytes of JSON per second
Stars: ✭ 15,115 (+6094.67%)
Mutual labels:  json, json-parser
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (-1.23%)
Mutual labels:  json, json-parser
Dynamodb Json
DynamoDB json util to load and dump strings of Dynamodb json format to python object and vise-versa
Stars: ✭ 114 (-53.28%)
Mutual labels:  json, json-parser
Gitlogg
💾 🧮 🤯 Parse the 'git log' of multiple repos to 'JSON'
Stars: ✭ 102 (-58.2%)
Mutual labels:  json, json-parser
Spotify Json
Fast and nice to use C++ JSON library.
Stars: ✭ 145 (-40.57%)
Mutual labels:  json, json-parser
Simplejson
simplejson is a simple, fast, extensible JSON encoder/decoder for Python
Stars: ✭ 1,372 (+462.3%)
Mutual labels:  json, json-parser
Poison
An incredibly fast, pure Elixir JSON library
Stars: ✭ 1,898 (+677.87%)
Mutual labels:  json, json-parser
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (-12.3%)
Mutual labels:  json, model
Simdjson php
simdjson_php bindings for the simdjson project. https://github.com/lemire/simdjson
Stars: ✭ 90 (-63.11%)
Mutual labels:  json, json-parser
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+4100%)
Mutual labels:  json, json-parser
Web Database Analytics
Web scrapping and related analytics using Python tools
Stars: ✭ 175 (-28.28%)
Mutual labels:  json, json-parser

WHC_Model

Build Status Pod Version Pod Platform Pod License 简介

  • 高效: 深度递归高性能解析架构,性能超过目前主流JsonModel,MJExtension...
  • 继承: 支持model类继承其他model类
  • 安全: 自动处理json中的null
  • 优势: 高容错能力(model类属性名称和json里key名称不区分大小写)
  • 强大: 支持自定义模型类属性名称以及类型别名设置
  • 特性: 支持反射指定json路径key来解析指定的节点json对象
  • 嵌套: 支持json或者model类的无限嵌套,json->model ,model->json的转换
  • 附加: 支持模型对象归档解档以及copy操作
  • 咨询: 712641411
  • 作者: 吴海超

性能测试

Time lost (Benchmark 1000 times)

  • 查看性能测试请运行项目: Benchmark/ModelBenchmark.xcodeproj

要求

  • iOS 6.0 or later
  • Xcode 8.0 or later

集成

  • 使用CocoaPods:
    • pod 'WHC_Model'
  • 手工集成:
    • 导入文件夹WHC_ModelKit

用法

json -> model

/// jsonString 是一个比较复杂3000行的json文件,具体参考demo
    ModelObject * model = [ModelObject whc_ModelWithJson:jsonString];
    NSLog(@"model = %@\n\n\n",model);

model -> json

    NSString * modelString = [model whc_Json];
    NSLog(@"modelString = %@\n\n\n",modelString);

model - > NSDictionary

    NSDictionary * modelDict = [model whc_Dictionary];
    NSLog(@"modelDict = %@\n\n\n",modelDict);

四,指定路径只解析Head对象

    Head * head = [Head whc_ModelWithJson:jsonString keyPath:@"Head"];
    NSLog(@"head = %@\n\n\n",head);

五,指定路径只解析ResponseBody对象

    ResponseBody * body = [ResponseBody whc_ModelWithJson:jsonString keyPath:@"ResponseBody"];
    NSLog(@"ResponseBody = %@\n\n\n",body);

六,指定路径只解析PolicyRuleList集合中第一个对象

    PolicyRuleList * rule = [PolicyRuleList whc_ModelWithJson:jsonString keyPath:@"ResponseBody.PolicyRuleList[0]"];
    NSLog(@"rule = %@\n\n\n",rule);

###七,归档对象

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:body];
    NSLog(@"data = %@\n\n\n",data);

八,解归档对象

    ResponseBody * body = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    NSLog(@"body = %@\n\n\n",body);

九,模型对象复制

    ResponseBody * copyBody = body.copy;
    NSLog(@"copyBody = %@",copyBody);

自定义别名

/// 模型类可自定义属性名称
+ (NSDictionary <NSString *, NSString *> *)whc_ModelReplacePropertyMapper {
    return @{<json key名: 替换实际属性名>};
}
/// 模型数组/字典元素对象可自定义类
+ (NSDictionary <NSString *, Class> *)whc_ModelReplaceContainerElementClassMapper {
    return @{替换实际属性名 : 实际类};
}
/// 模型类可自定义属性类型
+ (NSDictionary <NSString *, Class> *)whc_ModelReplacePropertyClassMapper {
    return @{替换实际属性名 : 实际类};
}

推荐

文档


#pragma mark - json转模型对象 Api -

/** 说明:把json解析为模型对象
 *@param json :json数据对象
 *@return 模型对象
 */
+ (id)whc_ModelWithJson:(id)json;

/** 说明:把json解析为模型对象
 *@param json :json数据对象
 *@param keyPath :json key的路径
 *@return 模型对象
 */

+ (id)whc_ModelWithJson:(id)json keyPath:(NSString *)keyPath;


#pragma mark - 模型对象转json Api -

/** 说明:把模型对象转换为字典
 *@return 字典对象
 */

- (NSDictionary *)whc_Dictionary;

/** 说明:把模型对象转换为json字符串
 *@return json字符串
 */

- (NSString *)whc_Json;

#pragma mark - 模型对象序列化 Api -

/// 复制模型对象
- (id)whc_Copy;

/// 序列化模型对象
- (void)whc_Encode:(NSCoder *)aCoder;

/// 反序列化模型对象
- (void)whc_Decode:(NSCoder *)aDecoder;

期待

  • 如果您在使用过程中有任何问题,欢迎issue me! 很乐意为您解答任何相关问题!
  • 与其给我点star,不如向我狠狠地抛来一个BUG!
  • 如果您想要更多的接口来自定义或者建议/意见,欢迎issue me!我会根据大家的需求提供更多的接口!

Licenses

All source code is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].