有人知道如何将此响应映射到地幔对象吗?
我需要将这些内容提供给自定义类的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"
}
]
]
答案 0 :(得分:2)
请尝试针对identical issue
提及的以下代码段+ (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;
}];
}