Code Monkey home page Code Monkey logo

yyjson's Introduction

YYJSON

将JSON数据直接转成NSObject
支持 NSString,NSNumber,int,float,BOOL,NSArray,OtherModel。
Demo中有体现。


支持自己选择JSON解析器

  • NSData (YYJSON)

-(id)YYJSONObject

这个方法返回JSON对象,可以选择自己习惯的JSON解析库
可以自行查看源文件,我写了如下

  1. iOS自带的NSJSONSerialization
  1. JSONKit
  2. OKJSONParser (号称自己是最快的)
  3. JsonLiteParser (也是号称自己是最快的)

速度方面我没有进行测试


使用方法

-(id)toModel:(Class)modelClass;
传入一个modelClass返回一个modelClass的实例

=

-(id)toModel:(Class)modelClass forKey:(NSString *)key;
传入一个modelClass和key(json的key)返回一个modelClass实例

=

-(NSArray *)toModels:(Class)modelClass;
传入一个modelClass返回一个modelClass的集合

=

-(NSArray *)toModels:(Class)modelClass forKey:(NSString *)key;
传入一个modelClass和key(json的key)返回一个modelClass的集合

NSURL *url = [NSURL URLWithString:@"http://url.cn/DjjSlB"];  
NSData *data = [NSData dataWithContentsOfURL:url];  
NSArray *shots = [data toModels:[Shot class] forKey:@"shots"];  
Player *player = [shots[0] player];

支持自己绑定属性名和JSON对应的key

@interface NSObject (YYJSON)
//如果需要获取父类的属性,则重载此方法并且return YES
+ (BOOL)YYSuper;
//映射的字典
+ (NSDictionary *)YYJSONKeyDict;
//自定义绑定 
+ (void)bindYYJSONKey:(NSString *)jsonKey toProperty:(NSString *)property;
@end

####具体使用方法看Demo吧

yyjson's People

Contributors

dcty avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.