2016-08-26 49 views
-2

的具有1M的問題試圖封裝這句話中的常規功能。responseAsSlurper錯誤常規

-----------------------------------英里通話------- ------------------------

sizeOfferPrices = 
responseAsSlurper.Body.FlightPriceRS.PricedFlightOffers.PricedFlightOffer.OfferPrice.size(); 
offerAmount = getTotalPrice(sizeOfferPrices) 

--------------- --------------我的功能--------------------------------

def getTotalPrice (sizeOfferPrices){ 

    def strTravelersAssociated 
    def floatImporteViaje = 0 
    String [] arrTravelersAssociated 
    def offerAmountTemp 

     //recorremos los precios que se nos ha devuelto en la oferta 
     for(i=0; i<=sizeOfferPrices-1; i++){ 
      //obtenemos el precio 
      offerAmountTemp = responseAsSlurper.Body.FlightPriceRS.PricedFlightOffers.PricedFlightOffer.OfferPrice[i].RequestedDate.PriceDetail.TotalAmount.SimpleCurrencyPrice 
      offerAmountTemp = offerAmountTemp.toFloat(); 

      //obtenemos los datos de los viajeros asociados , casteamos a string y splitamos para obtener array 
      strTravelersAssociated = responseAsSlurper.Body.FlightPriceRS.PricedFlightOffers.PricedFlightOffer.OfferPrice[i].RequestedDate.Associations.AssociatedTraveler.TravelerReferences 
      strTravelersAssociated = strTravelersAssociated.toString(); 
      arrTravelersAssociated = strTravelersAssociated.tokenize(" "); 

      //obtenemos el numero de viajeros por oferta 
      intTravelersByOffer = arrTravelersAssociated.size().toInteger(); 

      //realizamos la multiplicaciónd viajeros por su oferta asociada 
      floatImporteViajeTemp = (offerAmountTemp * intTravelersByOffer).round(2); 
      floatImporteViaje = floatImporteViaje + floatImporteViajeTemp; 
     } 
     //obtenemos el precio total 
     amount = floatImporteViaje.round(2); 
     return amount 
} 

_________________________ERROR_________________________________________

groovy.lang.MissingPropertyException:沒有這樣的屬性 resposeAsSpluger

enter image description here

有什麼建議?非常感謝。

+0

歡迎堆棧溢出。目前您的問題可能會被關閉。請閱讀http://stackoverflow.com/help/mcve。 –

回答

0

的錯誤是無關的,你已經發布的功能,因爲它的出現被稱爲函數之前。在這裏你嘗試調用,因爲您嘗試訪問不存在的屬性responseAsSlurper在第一行出現的錯誤(getTotalPrice調用之前)的功能

sizeOfferPrices = responseAsSlurper.Body.FlightPriceRS.PricedFlightOffers.PricedFlightOffer.OfferPrice.size(); 
offerAmount = getTotalPrice(sizeOfferPrices) 

的代碼。

+0

非常感謝您的幫助 – Alx

相關問題