码迷,mamicode.com
首页 > Web开发 > 详细

JSONModel 简单例子

时间:2015-07-21 20:31:37      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

//  ProductModel.h
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import "JSONModel.h"

@interface ProductModel : JSONModel

@property (nonatomic,strong)NSString<Optional> * id1;
@property (nonatomic,strong)NSString<Optional> * name;
@property (nonatomic,strong)NSString<Optional> * price;

@end

//  ProductModel.m
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import "ProductModel.h"

@implementation ProductModel
+(JSONKeyMapper *)keyMapper{
    return [[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"id1",@"sss":@"xxxxx"}];
}
@end

 

//  test1Model.h
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import "JSONModel.h"

@protocol test2Model
@end

@interface test2Model : JSONModel
@property (nonatomic,strong)NSString<Optional> * id1;
@property (nonatomic,strong)NSString<Optional> * name;
@property (nonatomic,strong)NSString<Optional> * price;
@end



@interface test1Model : JSONModel
@property (nonatomic,strong)NSString<Optional> * order_id;
@property (nonatomic,strong)NSString<Optional> * total_price;
@property (nonatomic,strong)NSArray<test2Model,Optional> * product;
@end


//  test1Model.m
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import "test1Model.h"

@implementation test2Model

+(JSONKeyMapper *)keyMapper{
    return [[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"id1"}];
}

@end


@implementation test1Model

@end

 

//  ViewController.h
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

//
//  ViewController.m
//  JSONModel
//
//  Created by 张国锋 on 15/7/20.
//  Copyright (c) 2015年 张国锋. All rights reserved.
//

#import "ViewController.h"
#import "test1Model.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSDictionary *dic=[[NSDictionary alloc]init];
    test1Model *model=[[test1Model alloc]initWithDictionary:dic error:nil];
    /*
     @property (nonatomic,strong)NSString<Optional> * order_id;
     @property (nonatomic,strong)NSString<Optional> * total_price;
     @property (nonatomic,strong)NSArray<test2Model,Optional> * product;
     */
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

JSONModel 简单例子

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4665473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!