美文网首页
使用JSONModel嵌套model

使用JSONModel嵌套model

作者: ioido | 来源:发表于2016-10-21 22:26 被阅读0次
{
    "data":{
        "gy_num":"30",
        "pgs":[
               {
                   "pgs_id":"1",
                   "products":[
                               {
                                   "product_id":"1",
                               },
                               {
                                   "product_id":"2",
                               }
                               ]
               },
               {
                   "pgs_id":"2",
                   "products":[
                               {
                                   "product_id":"1",
                               },
                               {
                                   "product_id":"2",
                               }
                               ]
               }
               ]
    },
    "success":true,
    "msg":"",
    "code":"0"
}

ProductModel.h
@property (nonatomic, strong) NSString *product_id;
PGSModel.h
@property (nonatomic, strong) NSString *pgs_id;
@property (nonatomic, strong) NSArray<ProductModel *>* products;
GYModel.h
@property (nonatomic, strong) NSString *gy_id;
@property (nonatomic, strong) NSArray<PGSModel *>* pgs;
获取model
_gyModel = [[GYModel alloc] initWithDictionary:dicData error:&error];
_dataList = [NSMutableArray arrayWithArray:_gyModel.pgs]

如果使用cell.model的set方法报错:
invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution. libc++abi.dylib: terminate_handler unexpectedly threw an exception
cell里应该这样写:
cell.model = [PGSModel arrayOfModelsFromDictionaries:_dataList][indexPath.row];

相关文章

网友评论

      本文标题:使用JSONModel嵌套model

      本文链接:https://www.haomeiwen.com/subject/ojmcuttx.html