0

我有以下 Mantle 对象并想将字典转换为 Mantle 对象。但转换总是返回空的 MTLModel 对象。有任何想法吗?

//ABC.h

@interface ABC : MTLModel<MTLJSONSerializing>

@property (nonatomic, strong) NSString *Identifier;
@property (nonatomic, strong) NSString *Name;
@property (nonatomic, strong) NSString *ImageURLString;
@property (nonatomic, strong) NSString *Desc;
@property (nonatomic, strong) NSString *lastUpdated;

@end

// ABC.m

@implementation ABC

+ (NSDictionary *)JSONKeyPathsByPropertyKey {

    return @{
             @"Identifier" : @"id",
             @"Name" : @"name",
             @"Desc" : @"desc",
             @"ImageURLString" : @"image_url",
             @"lastUpdated" : @"last_updated_at"
             };
}

@end

调用代码:

ABC *abc = [MTLJSONAdapter modelOfClass:ABC.class fromJSONDictionary:tempDict error:NULL]; 

JSON字典是:

{
    desc = "asdadasdakjqewqwmsdnasdaksdasd";
    id = adsasdasdasdasd;
    "image_url" = "http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/abc.JPG";
    "last_updated_at" = "2015-07-25 04:22:39.851710";
    name = asdasdqwe;
}

结果 ABC 对象没有内容。无法弄清楚我在这里缺少什么。

有任何想法吗???

4

2 回答 2

0
id = adsasdasdasdasd;

需要是

id = "adsasdasdasdasd";
于 2016-04-04T03:31:53.070 回答
0

尝试使用此代码段并调试adapterError。可能有关于从 NSDictionary 到 Mantle 对象的转换的相关信息

//Create Mantle object from NSDictionary using MTLJSONSerialization
NSError *adapterError;
MTLModel *user = [MTLJSONAdapter modelOfClass:MTLModel.class fromJSONDictionary:dictionary error:&adapterError];

if(adapterError) {
    PrintError(adapterError)
    return nil;
}
于 2015-09-24T08:23:11.360 回答