使用JSONModel嵌套model

{
    "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];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容