【问题标题】:How to map an array of arrays in Mantle如何在 Mantle 中映射数组
【发布时间】:2015-07-16 05:45:24
【问题描述】:

有人知道如何将此响应映射到地幔对象吗?

我需要将这些添加到自定义类的 NSArray 中。但是 Mantle 文档没有提到如何做到这一点。

提前致谢。

 [
    [
        {
            "plu_id": "1744",
            "name": "With egg",
            "price": "2.00",
            "group": null
        }
    ],
    [
        {
            "plu_id": "1745",
            "name": "add roast chicken",
            "price": "3.00",
            "group": "1"
        },
        {
            "plu_id": "1749",
            "name": "add beef",
            "price": "4.00",
            "group": "1"
        }
    ]
]

【问题讨论】:

    标签: objective-c arrays json github-mantle


    【解决方案1】:

    请尝试下面提到的identical issuesn-p

    + (NSValueTransformer *)allRowsJSONTransformer
    {
        return [MTLValueTransformer transformerWithBlock:^id(NSArray *inSectionJSONArray) {
            NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithCapacity:inSectionJSONArray.count];
            for( NSArray *section in inSectionJSONArray )
            {
                NSError *error;
                NSArray *cardItemArray = [MTLJSONAdapter modelsOfClass:[CKMCardItem class] fromJSONArray:section error:&error];
                if( cardItemArray != nil )
                {
                    [sectionArray addObject:cardItemArray];
                }
            }
            return sectionArray;
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      • 2021-06-23
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多