Ios 包含来自多个JSON源的数据的JSONModel

Ios 包含来自多个JSON源的数据的JSONModel,ios,json,model,jsonmodel,Ios,Json,Model,Jsonmodel,我对JSONModel有一个相当基本的问题。假设我有以下JSON: {"items": [ { "id": 1, "title": "Bla", "category": 1 } ]} 还有这个: {"categories": [ { "id": 1, "name": "Category" } ]} 现在最简单的事情是将类别放在项目中,让JSONModel使用它。但是可能

我对JSONModel有一个相当基本的问题。假设我有以下JSON:

{"items": [
    {
        "id": 1, 
        "title": "Bla",
        "category": 1
    }
 ]} 
还有这个:

{"categories": [
    {
        "id": 1, 
        "name": "Category"
    }
 ]} 
现在最简单的事情是将类别放在项目中,让JSONModel使用它。但是可能有数百个条目共享几个类别,这些类别有几个属性,比如描述、URL和其他内容,这会破坏条目

我如何使用JSONModel以最佳方式将它们结合起来,或者另一个库会更好吗

我的模型目前如下所示:

@interface Item : JSONModel

@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* title;
@property (strong, nonatomic) Category* category;

@end

@interface Category : JSONModel

@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* name;

@end
试试这个

@protocol Item
@end

@interface Item : JSONModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* title;
@property (strong, nonatomic) Category* category;
@end

@interface Items : JSONModel
@property (strong, nonatomic) NSArray<Item> *items;
@end

@protocol Category
@end

@interface Category : JSONModel

@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString *name;
@end

@interface Categories : JSONModel
@property (strong, nonatomic) NSArray<Category> *categories;
@end

您的JSON是项目或类别的数组

我不知道JSONModel,但它是将项目放入类别的选项吗?您的示例是一个典型的组合a.k.a.包容关系。