2015-08-25 3 views
0

У меня возникла ошибка при попытке отобразить глубоко вложенные объекты из JSON с помощью RestKit. Во-первых, я пытаюсь сопоставить название отеля, которое работает нормально. Однако, когда я пытаюсь получить цену от «ChargeableRateInfo» из JSON я получаю следующее сообщение об ошибке:Отображение ошибок RestKit API Expedia

restkit.object_mapping:RKMappingOperation.m:652 WARNING: Failed mapping nested object: (null)

Вот JSON пример, который я пытаюсь к карте:

{ 
"HotelListResponse": { 
    "customerSessionId": "0ABAAA3E-7637-1591-4F62-5548AC792D42", 
    "numberOfRoomsRequested": 1, 
    "moreResultsAvailable": true, 
    "cacheKey": "-48763715:14f65548ac7:2d4e", 
    "cacheLocation": "10.186.170.62:7300", 
    "cachedSupplierResponse": { 
     "@supplierCacheTolerance": "NOT_SUPPORTED", 
     "@cachedTime": "0", 
     "@supplierRequestNum": "235", 
     "@supplierResponseNum": "1", 
     "@supplierResponseTime": "503", 
     "@candidatePreptime": "30", 
     "@otherOverheadTime": "5", 
     "@tpidUsed": "5001", 
     "@matchedCurrency": "true", 
     "@matchedLocale": "true" 
    }, 
    "HotelList": { 
     "@size": "1", 
     "@activePropertyCount": "235", 
     "HotelSummary": { 
      "@order": "0", 
      "@ubsScore": "1069912", 
      "hotelId": 206005, 
      "name": "Mediterranean Inn", 
      "address1": "425 Queen Anne Ave N", 
      "city": "Seattle", 
      "stateProvinceCode": "WA", 
      "postalCode": 98109, 
      "countryCode": "US", 
      "airportCode": "SEA", 
      "supplierType": "E", 
      "propertyCategory": 1, 
      "hotelRating": 3, 
      "confidenceRating": 70, 
      "amenityMask": 7799051, 
      "tripAdvisorRating": 4, 
      "tripAdvisorReviewCount": 1086, 
      "tripAdvisorRatingUrl": "http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/4.0-12345-4.gif", 
      "locationDescription": "Near Pacific Northwest Ballet", 
      "shortDescription": "<p><b>Property Location</b> <br />With a stay at Mediterranean Inn, you'll be centrally located in Seattle, steps from Key Arena and minutes from Seattle Children's Theatre. This family-friendly", 
      "highRate": 270, 
      "lowRate": 162, 
      "rateCurrencyCode": "USD", 
      "latitude": 47.62244, 
      "longitude": -122.35672, 
      "proximityDistance": 12.288694, 
      "proximityUnit": "MI", 
      "hotelInDestination": true, 
      "thumbNailUrl": "/hotels/1000000/900000/897600/897598/897598_108_t.jpg", 
      "deepLink": "http://www.travelnow.com/templates/55505/hotels/206005/overview?lang=en&currency=USD&standardCheckin=9/15/2015&standardCheckout=9/17/2015&roomsCount=1&rooms[0].adultsCount=2", 
      "RoomRateDetailsList": { 
       "RoomRateDetails": { 
        "roomTypeCode": 15567, 
        "rateCode": 15567, 
        "maxRoomOccupancy": 2, 
        "quotedRoomOccupancy": 2, 
        "minGuestAge": 0, 
        "roomDescription": "Petite Room, 1 Queen Bed, Kitchenette", 
        "propertyAvailable": true, 
        "propertyRestricted": false, 
        "expediaPropertyId": 897598, 
        "RateInfos": { 
         "@size": "1", 
         "RateInfo": { 
          "@priceBreakdown": "true", 
          "@promo": "true", 
          "@rateChange": "false", 
          "RoomGroup": { 
           "Room": { 
            "numberOfAdults": 2, 
            "numberOfChildren": 0, 
            "rateKey": "81423e04-b223-4ea1-807a-8812c13b31be", 
            "ChargeableNightlyRates": [ 
             { 
              "@baseRate": "270.00", 
              "@rate": "162.00", 
              "@promo": "true" 
             }, { 
              "@baseRate": "270.00", 
              "@rate": "162.00", 
              "@promo": "true" 
             } 
            ] 
           } 
          }, 
          "ChargeableRateInfo": { 
           "@averageBaseRate": "270.00", 
           "@averageRate": "162.00", 
           "@commissionableUsdTotal": "324.00", 
           "@currencyCode": "USD", 
           "@maxNightlyRate": "162.00", 
           "@nightlyRateTotal": "324.00", 
           "@grossProfitOffline": "54.87", 
           "@grossProfitOnline": "81.40", 
           "@surchargeTotal": "69.07", 
           "@total": "393.07", 
           "NightlyRatesPerRoom": { 
            "@size": "2", 
            "NightlyRate": [ 
             { 
              "@baseRate": "270.00", 
              "@rate": "162.00", 
              "@promo": "true" 
             }, { 
              "@baseRate": "270.00", 
              "@rate": "162.00", 
              "@promo": "true" 
             } 
            ] 
           }, 
           "Surcharges": { 
            "@size": "1", 
            "Surcharge": { 
             "@type": "TaxAndServiceFee", 
             "@amount": "69.07" 
            } 
           } 
          }, 
          "nonRefundable": false, 
          "rateType": "MerchantStandard", 
          "promoId": 212134483, 
          "promoDescription": "24 hour deal: save 40%", 
          "promoType": "Standard", 
          "currentAllotment": 3 
         } 
        } 
       } 
      } 
     } 
    } 
} 
} 

И вот мой код, где Я пытаюсь сопоставить этот JSON:

- (void)configureRestKit 
{ 
// initialize AFNetworking HTTPClient 
NSURL *baseURL = [NSURL URLWithString:@"http://api.ean.com"]; 
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL]; 

// initialize RestKit 
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client]; 


// setup object mappings 
RKObjectMapping *hotelMapping = [RKObjectMapping mappingForClass:[HotelList class]]; 
[hotelMapping addAttributeMappingsFromArray:@[@"name"]]; 



RKObjectMapping *priceMapping = [RKObjectMapping mappingForClass:[ChargeableRateInfo class]]; 
[priceMapping addAttributeMappingsFromDictionary:@{@"total": @"total"}]; 

[hotelMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"RoomRateDetailsList.RoomRateDetails.RateInfos.RateInfo.ChargeableRateInfo" toKeyPath:@"chargeableRateInfo" withMapping:priceMapping]]; 


// register mappings with the provider using a response descriptor 
RKResponseDescriptor *responseDescriptor = 
[RKResponseDescriptor responseDescriptorWithMapping:hotelMapping 
              method:RKRequestMethodGET 
             pathPattern:@"/ean-services/rs/hotel/v3/list" 
              keyPath:@"HotelListResponse.HotelList.HotelSummary" 
             statusCodes:[NSIndexSet indexSetWithIndex:200]]; 

[objectManager addResponseDescriptor:responseDescriptor]; 


} 

Кто-нибудь знает, как это решить? Спасибо

ответ

0

Ключ отображения должен быть @total на основе содержимого в JSON.

Это не идеальный, так как @ - специальный символ в KVC, который использует RestKit. Вам нужно будет обойти это с чем-то от this answer или this pull request.