productmodel.h// jsonmodel//// Created by Feng on 15/7/20.// Copyright (c) 2015 Feng. 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 Feng on 15/7/20.// Copyright (c) 2015 Feng. All rights reserved.//#import "ProductModel.h" @implementation productmodel+ (Jsonkeymapper *) keymapper{ return [[ Jsonkeymapper Alloc] initwithdictionary:@{@ "id": @ "ID1", @ "SSS": @ "xxxxx"}];} @end
test1model.h// jsonmodel//// Created by Feng on 15/7/20.// Copyright (c) 2015 Feng. 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 Feng on 15/7/20.// Copyright (c) 2015 Feng. 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 Feng on 15/7/20.//Copyright (c) 2015 Feng. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller@end//// viewcontroller.m//jsonmodel////Created by Feng on 15/7/20.//Copyright (c) 2015 Feng. 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 resourcesThat can is recreated.} @end
Jsonmodel Simple Example