Giter VIP home page Giter VIP logo

hbduckdemo's Introduction

HBDuckDemo json最强解析

  1. 利用nsproxy创建鸭子对象,一句话解析json
  2. 面向protocol编程
  3. 参考链接 [http://blog.sunnyxx.com/2014/08/24/objc-duck/]
- (void)demoJsonEntity
{
    NSString *json = @"{\"name\": \"sunnyxx\", \"sex\": \"boy\", \"age\": 24,\"subuser\":{\"name\":\"huangbo\"}}";
    id<HBDuckEntity, XXUserEntity> entity= HBDuckEntityCreateWithJSON(json);
    
    NSLog(@"%@, %@, %@", entity.jsonString, entity.name, entity.age);
    entity.name = @"east north";
    entity.age = @100;
    entity.other = @"aaaa";
    NSLog(@"%@",entity.subuser.name);  
    
    NSLog(@"%@, %@", entity.name, entity.age);
  
    NSString * filapath =[[NSBundle mainBundle] pathForResource:@"testjson" ofType:@"json"] ;
    NSData * data = [NSData dataWithContentsOfFile:filapath];
    NSString * json2 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
     
    id<HBDuckEntity, SMDResponse> smdentity = HBDuckEntityCreateWithJSON(json2);
    NSLog(@"%@",smdentity.code);
    NSLog(@"%@",smdentity.message);
    NSLog(@"%@",smdentity.data.total);
    NSLog(@"%@",smdentity.data.data);
    NSLog(@"%@",smdentity.data);
    NSArray * array = smdentity.data.data;
    id<SMDRespDataData>  info = array[0];
    id<SMDRespDataAskerUser> askUser = info.askUser;
    id<SMDRespDataQaInfo> qainfo = info.qaInfo;
    NSLog(@"%@ %@ %@",info,askUser,qainfo);
     
}

hbduckdemo's People

Stargazers

 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.