0

我正在使用 RESTKit 进行 GET 请求,当我进行对象映射时,它不起作用。但是,它总是说它在映射结果中映射了一个对象,但我不知道那是什么或如何让它映射其余对象。我到底做错了什么导致映射结果显示为一个映射的对象,我如何让它映射所有正确的对象?

这是映射结果:

Mapping Result: (
    "<Info: 0x9c91130>"
)

这是我的 GET 请求://RK Logging RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
NSString *urlString = [NSString stringWithFormat:@"https://beta.stuff.com/"];
NSURL *url = [NSURL URLWithString:urlString];

//Object Mapping
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Info class]];
[mapping addAttributeMappingsFromDictionary:@{@"name": @"name", @"id": @"strenuusID", @"location_specialties.address": @"address", @"location_specialties.state": @"state", @"location_specialties.zip": @"zipcode", @"location_specialties.address_lines": @"address_lines"}];

NSString *pathPatternString = [NSString stringWithFormat:@"stuff/%@/stuff2/%@/", moreresultsVCSobj.projectNumber, moreresultsVCSobj.doctorStuff];

//Response Descriptor
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
                                                                                                method:RKRequestMethodGET
                                                                                           pathPattern:pathPatternString
                                                                                               keyPath:@""
                                                                                           statusCodes:statusCodeSet];

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:url];
[manager addResponseDescriptor:responseDescriptor];
[manager.HTTPClient setDefaultHeader:@"Auth-Token" value:moreresultsVCSobj.userAuthToken];

Info *info = [Info new];
[manager getObject:info path:pathPatternString parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
    NSLog(@"Mapping Result: %@", mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error)
{
    NSLog(@"Error: %@", error);
}];

这是我正在解析的 JSON:

response.body=
{
"name": "Name, Generic N,   DDS",
"id": 123456,
"npi": "1234567890",
"hospitality": false,
"groupiness": [
    "Other"
],
"client_ids": null,
"has_comments": false,
"comment_count": 0,
"is_facility": false,
"location_specialties": [
    {
        "id": 123456,
        "address_id": 454345,
        "address": "1234 Rifle    Rd",
        "state": "Al",
        "zip": "43543",
        "address_lines": [
            "1234 Rifle Rd",
            "Generic Town, Al    43543",
            "111-222-    3344"
        ],
        "latitude": 21432234,
        "longitude": 432432,
        "is_validated": true,
        "providers_at_address_count": 2,
        "specialties": [
            {
                "name": "Dentists",
                "plans": [
                    {
                        "name": "Plan name",
                        "lists_specialty": true
                    },
                    {
                        "name": "Plane name 2",
                        "lists_specialty": true
                    },
                    {
                        "name": "Plan name 3",
                        "lists_specialty": true
                    }
                ]
            }
        ]
    },
    [
        {
            "id": 123456,
            "address_id": 454345,
            "address": "1234 Rifle      Rd",
            "state": "Al",
            "zip": "43543",
            "address_lines": [
                "1234 Rifle Rd",
                "Generic Town, Al    43543",
                "111-222-        3344"
            ],
            "latitude": 21432234,
            "longitude": 432432,
            "is_validated": true,
            "providers_at_address_count": 2,
            "specialties": [
                {
                    "name": "Dentists",
                    "plans": [
                        {
                            "name": "Plan name",
                            "lists_specialty": true
                        },
                        {
                            "name": "Plane name 2",
                            "lists_specialty": true
                        },
                        {
                            "name": "Plan name 3",
                            "lists_specialty": true
                        }
                    ]
                }
            ]
        },
        "hospital_detail": null,
        "tags": [

        ]
    }

编辑:这是我的 Info.h 文件。我尝试检查映射其他内容,例如名称,但它们仍然不起作用。

#import <Foundation/Foundation.h>

@interface Info : NSObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *strenuusID;
@property (nonatomic, copy) NSString *npi;
@property (nonatomic, copy) NSArray *specialty_search_groups;
@property (nonatomic, copy) NSArray *address_lines;
@property (nonatomic, copy) NSArray *address;
@property (nonatomic, copy) NSString *state;
@property (nonatomic, copy) NSString *zipcode;
@property (nonatomic, copy) NSString *planName;

@end
4

1 回答 1

0

你得到一个结果对象,因为你的 JSON 是一本字典。您的映射和响应描述符是根据单个对象编写的。

这个映射:

@"location_specialties.address": @"address"

不起作用,因为location_specialties它是一个数组,所以无法访问该地址。除非您的目的地是数组变量,否则它可能会起作用。

您需要Info详细检查对象的内容并在跟踪日志中查找问题。如果您仍然有问题,您需要提供有关Info对象本身的详细信息。

于 2013-10-05T18:23:33.293 回答