JSONModel 多级

模型里面套模型


#import <JSONModelD/JSONModel.h>
#import "ExamListModel.h"

//@protocol ExamListModel
//@end
//
//@interface ExamListModel : JSONModel
//@property (assign, nonatomic) int id;
//@property (strong, nonatomic) NSString* name;
//@property (assign, nonatomic) float price;
//@end
//
//@implementation ExamListModel
//@end
@interface ExamModel : JSONModel

@property (nonatomic, strong)NSString *id;
@property (nonatomic, strong)NSString *name;
@property (nonatomic, assign)NSInteger questionType;
@property (nonatomic, strong)NSString *score;
@property (nonatomic, strong)NSString *answer;
@property (nonatomic, strong)NSString *orderNum;

@property (nonatomic, strong) NSMutableArray *oldListData;

@property (nonatomic, strong)NSMutableArray <ExamListModel*>* qOptions;

@end


其中后台返回套的模型数组的名字为qOptions


#import "ExamModel.h"

@implementation ExamModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    
    return YES;
    
}

- (NSMutableArray *)qOptions{
    if (!_qOptions) {
        _qOptions = [NSMutableArray array];
    }
    return _qOptions;
}

+ (NSString *)protocolForArrayProperty:(NSString *)propertyName
{
    if ([propertyName isEqualToString:@"qOptions"]) {
        return NSStringFromClass([ExamListModel class]);
    } else {
        return nil;
    }
}


#import <JSONModelD/JSONModel.h>
//"id": 61463,
//"name": "临沂",
//"optionName": "B",
//"question": 381226,
//"orderNum": 2

@interface ExamListModel : JSONModel
@property (nonatomic, copy) NSString *id;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *optionName;
@property (nonatomic, copy) NSString *question;
@property (nonatomic, copy) NSString *orderNum;
@end


#import "ExamListModel.h"

@implementation ExamListModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值