RestKit 0.20を使用して次のJSON応答を逆シリアル化したいのですが、失敗し、legsはとして定義されNSSet
、常に。を返しますnil
。このコードの何が問題になっていますか?
{
"Flights": [{
"Id": "1",
"Price": 100,
"Duration": 60,
"RemainingSeats": 10,
"Legs": [{
"Airline": "Tukish Airlines",
"FlightNumber": "A111",
"TakeOffDate": "\/Date(1355915405327)\/",
"TakeOffAirport": "AHL",
"LandingDate": "\/Date(1356001805327)\/",
"LandingAirport": "ERC",
"Duration": 60,
"TransportDuration": 0
}]
}]
}
RKObjectMapping* legMapping = [RKObjectMapping mappingForClass:[Leg class]];
[legMapping addAttributeMappingsFromDictionary:@{
@"Airline": @"airline",
@"FlightNumber": @"flightNumber",
@"TakeOffDate": @"takeOffDate",
@"TakeOffAirport": @"takeOffAirport",
@"LandingDate": @"landingDate",
@"LandingAirport": @"landingAirport",
@"Duration": @"duration",
@"TransportDuration": @"transportDuration",
}];
RKObjectMapping* flightMapping = [RKObjectMapping mappingForClass:[Flight class]];
[flightMapping addAttributeMappingsFromDictionary:@{
@"Id": @"id",
@"Price": @"price",
@"Duration": @"duration",
@"RemainingSeats": @"remainingSeats"
}];
RKRelationshipMapping *flightLegsMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Legs" toKeyPath:@"legs" withMapping:legMapping];
[flightMapping addRelationshipMappingWithSourceKeyPath:@"legs" mapping:flightLegsMapping.mapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:flightMapping pathPattern:nil keyPath:@"Flights" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
NSString *isRoundTripString = isRoundTrip ? @"true" : @"false";
NSDateFormatter *gmtFormatter = [[NSDateFormatter alloc] init];
[gmtFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *departureDateString = [gmtFormatter stringFromDate:departureDate];
NSString *returnDateString = [gmtFormatter stringFromDate:returnDate];
NSString *directFlightsOnlyString = directFlightsOnly ? @"true" : @"false";
NSString *urlString = [NSString stringWithFormat: @"http://parallels-win7:8132/flight/flights?isRoundTrip=%@&departureAirport=%@&arrivalAirport=%@&departureDate=%@&returnDate=%@&adultCount=%d&childCount=%d&babyCount=%d&oldPeopleCount=%d&studentCount=%d&directFlightsOnly=%@", isRoundTripString, departureAirport, arrivalAirport, departureDateString, returnDateString, adultCounts, childCount, babyCount, oldPeopleCount, studentCount, directFlightsOnlyString];
NSURL *url = [NSURL URLWithString: urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKObjectRequestOperation *objectRequestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
success(mappingResult.array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
failure(error);
}];
[objectRequestOperation start];
mappingResult.array
いっぱいですが、足は空です。