我想通过restkit加载以下JSON。我正在使用Restkit 0.2.3。
JSON数据:
{
"meta": {
"limit": 25,
"cache-expiry": 3600
},
"objects": [
{
"name": "TREATmachine",
"locality": "San Francisco",
"street_address": "20th & Morrison S.E.",
"cuisines": [
"vegan",
"european"
],
"region": "CA",
"phone": "(503) 308-8851",
"postal_code": "94110",
"categories": [
"other",
"restaurant"
],
"has_menu": true,
}
]
}
现在我为此声明了这个类来处理所有元素
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* locality;
@property (nonatomic, retain) NSString* street_address;
@property (nonatomic, retain) NSArray * cuisines;
@property (nonatomic, retain) NSString* region;
@property (nonatomic, retain) NSString* phone;
@property (nonatomic, retain) NSString* postal_code;
@property (nonatomic, retain) NSArray * categories;
@property (assign) BOOL has_menu;
现在映射就像这样,
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Location class]];
[mapping addAttributeMappingsFromArray:@[@"name",@"locality", @"street_address", @"region",
@"phone", @"postal_code", @"country", @"lat", @"website_url", @"resource_uri"]];
[mapping addAttributeMappingsFromDictionary:@{ @"venueID": @"id"}];
之后我创建了一个
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
responseDescriptorWithMapping:mapping method:RKRequestMethodGET pathPattern:@"/Locations
/search/" keyPath:@"objects" statusCodes:statusCodeSet];
它在获取数据时工作正常,但我遇到的问题是我总是得到一个空的对象,其中没有数据。
我没有收到失败或错误消息,只是空对象。
我错过了什么?
编辑:输入响应描述符代码。
答案 0 :(得分:0)
在从@Wain获得记录的好主意后,我将以下代码添加到我的视图控制器
RKLogConfigureByName("RestKit", RKLogLevelWarning);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
它基本上告诉我,我没有正确映射我的数据。
我不知道人们是否有关于跟踪级别映射代码的去向的建议?在哪个文件?的AppDelegate?