0

请帮助从以下 JSON 进行映射

{
meta: {}
notifications: []
response: {
suggestedFilters: {}
suggestedRadius: 922
headerLocation: "Manhattan"
headerFullLocation: "Manhattan"
headerLocationGranularity: "city"
totalResults: 
suggestedBounds: {}
groups: [
{
type: "Recommended Places"
name: "recommended"
items: [
{
reasons: {}
venue: {
id: "430d0a00f964a5203e271fe3"
name: "Brooklyn Bridge Park"
contact: {}
location: {}
categories: []
verified: 
stats: {}
likes: {}
like: 
rating: 
hours: {}
specials: {}
photos: {}
hereNow: {}
}
tips: []
referralId: "e-0-430d0a00f964a5203e271fe3-0"
}
{

到带有属性的地点对象

@property (nonatomic, copy) NSString *ID;
@property (nonatomic, copy) NSString *name;

我需要将响应 > 组 > 地点 > id 映射到“id”和响应 > 组 > 地点 > 名称到“名称”

我写这个

NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider venueMapping]
                                                                                            method:RKRequestMethodGET
                                                                                       pathPattern:@"/v2/venues/explore"
                                                                                           keyPath:@"response"
                                                                                       statusCodes:statusCodeSet];

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/venues/explore?ll=40.7,-74&oauth_token=%@",
                                       [[DataManager sharedManager] baseURL], [[DataManager sharedManager] anonymusUserAccessToken]]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    RKObjectRequestOperation *operation =  [[RKObjectRequestOperation alloc] initWithRequest:request
                                                                         responseDescriptors:@[responseDescriptor]];

    [operation setCompletionBlockWithSuc.....

但它不工作

谢谢

4

1 回答 1

1

您不能直接映射到该级别,因为映射无法处理对 2 个不同数组(组和项)的索引。您需要创建处理这些数组的映射,在这种情况下,通过创建并映射到容器对象(组),以便您可以处理 items 数组(及其包含的场所)。

于 2014-02-18T23:50:21.967 回答