2016-10-02 58 views
0

我開始使用sky-scanner API在Android上使用volley。我能夠輪詢API的響應,但是我不知道如何解析發送的響應中的json,請參閱下面的json。 json的響應非常大,我從來沒有用過這樣的響應,因此我不知道該如何處理。JSON解析在skyscanner定價api

有人能幫我解決這個問題嗎?沒有任何人爲skyscanner爲android完成示例實現。 要解析JSON響應以獲取價格,代理商,航班號,運營商,航班的持續時間,航班的圖像URL。

{ 
    "SessionKey": "97d1_ecilpojl_A", 
    "Query": { 
    "Country": "IN", 
    "Currency": "INR", 
    "Locale": "en-us", 
    "Adults": 1, 
    "Children": 0, 
    "Infants": 0, 
    "OriginPlace": "12627", 
    "DestinationPlace": "11712", 
    "OutboundDate": "2016-10-09", 
    "LocationSchema": "Default", 
    "CabinClass": "Economy", 
    "GroupPricing": false 
    }, 
    "Status": "UpdatesComplete", 
    "Itineraries": [ 
    { 
     "OutboundLegId": "12627-1610091100-AI-1-11712-1610091515", 
     "PricingOptions": [ 
     { 
      "Agents": [ 
      1963108 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 19391.08, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fat24%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      2176206 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20190, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fcpin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      4575202 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20315, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fyatr%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      4056270 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20457.92, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftpin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      1943172 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20876, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fakbt%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      3987150 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20888.5, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ft2in%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32672%7c446%7c12627%7c2016-10-09T11%3a00%7c10957%7c2016-10-09T12%3a35%3bflight%7c-" 
     }, 
     { 
      "Agents": [ 
      4035534 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 20959.41, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftgin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      1964238 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 21207.92, 
      "DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fatin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      4060673 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 21782, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftrea%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      3911604 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 21782, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fsast%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      2391001 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 21782, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http1.prod_0148f8394d6c2b79a407121f74dce6e1%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a13" 
     }, 
     { 
      "Agents": [ 
      4260937 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 22217.64, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fviai%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      3929744 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 22417.66, 
      "DeeplinkUrl": "deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http32672%26passengers%3d1%2c0%2c0%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d22417.66%26is_npt%3dfalse%26is_multipart%3dfal 
     } 
     ], 
     "BookingDetailsLink": { 
     "Uri": "/apiservices/pricing/v1.0/97d115d901944a33a4084a4a3170905f_ecilpojl_A1EA190098863E15CE039BCA9C3B1D16/booking", 
     "Body": "OutboundLegId=12627-1610091100-AI-1-11712-1610091515&InboundLegId=", 
     "Method": "PUT" 
     } 
    }, 
    { 
     "OutboundLegId": "12627-1610090820-9W,AI-1-11712-1610091515", 
     "PricingOptions": [ 
     { 
      "Agents": [ 
      1963108 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 37113.61, 
      "DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fat24%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32177%7c2367%7c12627%7c2016-" 
     }, 
     { 
      "Agents": [ 
      2176206 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 38374, 
      "DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fcpin%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32177%7c2367%7c12627%7c2016-10-09T08%3a20%7c10957%7c2016-10-09T09%3a45%3bflight%7c-" 
     }, 
     { 
      "Agents": [ 
      4056270 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 38854.31, 
      "DeeplinkUrl": "http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftpin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      1964238 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 39604.31, 
      "DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fatin%2f1%2f12627.11712.2016-10-" 
     }, 
     { 
      "Agents": [ 
      2627411 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 39932.95, 
      "DeeplinkUrl": "/deeplink/v2?_1.prod_8365f3bbc5ef11ab38406bb350796374%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a12" 
     }, 
     { 
      "Agents": [ 
      2042574 
      ], 
      "QuoteAgeInMinutes": 5, 
      "Price": 43940.34, 
      "DeeplinkUrl": "/deeplink/v2?32672%26passengers%3d1%2c0%2c0%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d43940.34%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3dd4cc5531-1a4b-4c76-a063-447e7a8baeea%26deeplink_ids%3dap-northeast-1.prod_0b228b45aaf97f3276f40ee4109e8faf%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a13" 
     } 
     ], 
     "BookingDetailsLink": { 
     "Uri": "/apiservices/pricing/v1.0/97d115d901944a33a4084a4a3170905f_ecilpojl_A1EA190098863E15CE039BCA9C3B1D16/booking", 
     "Body": "OutboundLegId=12627-1610090820-9W,AI-1-11712-1610091515&InboundLegId=", 
     "Method": "PUT" 
     } 
    } 
    ], 
    "Legs": [ 
    { 
     "Id": "12627-1610091100-AI-1-11712-1610091515", 
     "SegmentIds": [ 
     1, 
     2 
     ], 
     "OriginStation": 12627, 
     "DestinationStation": 11712, 
     "Departure": "2016-10-09T11:00:00", 
     "Arrival": "2016-10-09T15:15:00", 
     "Duration": 255, 
     "JourneyMode": "Flight", 
     "Stops": [ 
     10957 
     ], 
     "Carriers": [ 
     841 
     ], 
     "OperatingCarriers": [ 
     841 
     ], 
     "Directionality": "Outbound", 
     "FlightNumbers": [ 
     { 
      "FlightNumber": "446", 
      "CarrierId": 841 
     }, 
     { 
      "FlightNumber": "433", 
      "CarrierId": 841 
     } 
     ] 
    }, 
    { 
     "Id": "12627-1610090820-9W,AI-1-11712-1610091515", 
     "SegmentIds": [ 
     3, 
     2 
     ], 
     "OriginStation": 12627, 
     "DestinationStation": 11712, 
     "Departure": "2016-10-09T08:20:00", 
     "Arrival": "2016-10-09T15:15:00", 
     "Duration": 415, 
     "JourneyMode": "Flight", 
     "Stops": [ 
     10957 
     ], 
     "Carriers": [ 
     471, 
     841 
     ], 
     "OperatingCarriers": [ 
     471, 
     841 
     ], 
     "Directionality": "Outbound", 
     "FlightNumbers": [ 
     { 
      "FlightNumber": "433", 
      "CarrierId": 841 
     }, 
     { 
      "FlightNumber": "2367", 
      "CarrierId": 471 
     } 
     ] 
    } 
    ], 
    "Segments": [ 
    { 
     "Id": 1, 
     "OriginStation": 12627, 
     "DestinationStation": 10957, 
     "DepartureDateTime": "2016-10-09T11:00:00", 
     "ArrivalDateTime": "2016-10-09T12:35:00", 
     "Carrier": 841, 
     "OperatingCarrier": 841, 
     "Duration": 95, 
     "FlightNumber": "446", 
     "JourneyMode": "Flight", 
     "Directionality": "Outbound" 
    }, 
    { 
     "Id": 2, 
     "OriginStation": 10957, 
     "DestinationStation": 11712, 
     "DepartureDateTime": "2016-10-09T13:40:00", 
     "ArrivalDateTime": "2016-10-09T15:15:00", 
     "Carrier": 841, 
     "OperatingCarrier": 841, 
     "Duration": 95, 
     "FlightNumber": "433", 
     "JourneyMode": "Flight", 
     "Directionality": "Outbound" 
    }, 
    { 
     "Id": 3, 
     "OriginStation": 12627, 
     "DestinationStation": 10957, 
     "DepartureDateTime": "2016-10-09T08:20:00", 
     "ArrivalDateTime": "2016-10-09T09:45:00", 
     "Carrier": 471, 
     "OperatingCarrier": 471, 
     "Duration": 85, 
     "FlightNumber": "2367", 
     "JourneyMode": "Flight", 
     "Directionality": "Outbound" 
    } 
    ], 
    "Carriers": [ 
    { 
     "Id": 841, 
     "Code": "AI", 
     "Name": "Air India", 
     "ImageUrl": "http://s1.apideeplink.com/images/airlines/AI.png", 
     "DisplayCode": "AI" 
    }, 
    { 
     "Id": 471, 
     "Code": "9W", 
     "Name": "Jet Airways", 
     "ImageUrl": "http://s1.apideeplink.com/images/airlines/9W.png", 
     "DisplayCode": "9W" 
    } 
    ], 
    "Agents": [ 
    { 
     "Id": 1963108, 
     "Name": "Mytrip", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/at24.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "BookingNumber": "+448447747881", 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 2176206, 
     "Name": "Cheapticket.in", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/cpin.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4575202, 
     "Name": "Yatra.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/yatr.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "BookingNumber": "18001029900", 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4056270, 
     "Name": "Tripsta", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/tpin.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 1943172, 
     "Name": "AkbarTravels.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/akbt.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 3987150, 
     "Name": "Travel2be", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/t2in.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4035534, 
     "Name": "Travelgenio", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/tgin.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 1964238, 
     "Name": "airtickets", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/atin.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4060673, 
     "Name": "Traveasy.co.in", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/trea.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 3911604, 
     "Name": "Sastiticket.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/sast.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 2391001, 
     "Name": "EaseMyTrip.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/emti.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4260937, 
     "Name": "via.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/viai.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 3929744, 
     "Name": "Simplio", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/simp.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 2627411, 
     "Name": "GotoGate", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/gtas.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 2042574, 
     "Name": "Bravofly", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/bfin.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 1882712, 
     "Name": "ebookers", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/a178.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": true, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 4366985, 
     "Name": "Wegoby.com", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/wgby.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 3291237, 
     "Name": "My Travel Genie", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/mtge.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 3588558, 
     "Name": "Tripair", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/pein.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "Type": "TravelAgent" 
    }, 
    { 
     "Id": 2834897, 
     "Name": "Air India", 
     "ImageUrl": "http://s1.apideeplink.com/images/websites/inda.png", 
     "Status": "UpdatesComplete", 
     "OptimisedForMobile": false, 
     "BookingNumber": "18001801407", 
     "Type": "Airline" 
    } 
    ], 
    "Places": [ 
    { 
     "Id": 12627, 
     "ParentId": 3462, 
     "Code": "IXL", 
     "Type": "Airport", 
     "Name": "Leh" 
    }, 
    { 
     "Id": 10957, 
     "ParentId": 3401, 
     "Code": "DEL", 
     "Type": "Airport", 
     "Name": "New Delhi" 
    }, 
    { 
     "Id": 11712, 
     "ParentId": 3424, 
     "Code": "GAY", 
     "Type": "Airport", 
     "Name": "Gaya" 
    }, 
    { 
     "Id": 3462, 
     "ParentId": 170, 
     "Code": "IXL", 
     "Type": "City", 
     "Name": "Leh" 
    }, 
    { 
     "Id": 3401, 
     "ParentId": 170, 
     "Code": "DEL", 
     "Type": "City", 
     "Name": "New Delhi" 
    }, 
    { 
     "Id": 3424, 
     "ParentId": 170, 
     "Code": "GAY", 
     "Type": "City", 
     "Name": "Gaya" 
    }, 
    { 
     "Id": 170, 
     "Code": "IN", 
     "Type": "Country", 
     "Name": "India" 
    } 
    ], 
    "Currencies": [ 
    { 
     "Code": "INR", 
     "Symbol": "₹", 
     "ThousandsSeparator": ",", 
     "DecimalSeparator": ".", 
     "SymbolOnLeft": true, 
     "SpaceBetweenAmountAndSymbol": false, 
     "RoundingCoefficient": 0, 
     "DecimalDigits": 2 
    } 
    ] 
} 
+0

那麼你可以告訴我們json響應嗎?和其他任何相關的代碼。 [如何問](http://stackoverflow.com/help/how-to-ask) – AgataB

+0

我粘貼json響應在這裏[鏈接](http://pastebin.com/SMw1TTu6),pojo類我能從上面的json響應創建是這樣的:[link](http://pastebin.com/080AvUd3)。基本上我想在回收站視圖中顯示最便宜到最便宜的航班(每一行都會顯示航班名稱,價格,航程,飛行標誌),因爲我需要將響應中的數據推送到arraylist,必須解析,我需要幫助解析響應。 – ghap

+0

請將它粘貼到問題中,而不是鏈接。只需編輯問題。 – AgataB

回答

0

如果你能拉JSON數據,然後嘗試使用這個js腳本:

  1. 確保添加的jQuery
  2. 更改網址變量的值與會話調查您創建的網址

注意:請注意,當您嘗試在此處運行此腳本時,您會遇到交叉原點錯誤。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
 

 
(function(window, document, $){ 
 

 
    var app = {}; 
 

 

 
    app.init = function() 
 
    { 
 
     app.flightsGeo(); 
 
    }; 
 
    
 
    app.flightsGeo = function() 
 
    {  
 
     // the session poll url you created 
 
     var url = 'http://business.skyscanner.net/apiservices/pricing/hk1/v1.0/<sessionKey>?apikey=<apikey>'; 
 
     $.ajax({ 
 
      type: "GET", 
 
      url: url, 
 
      dataType: 'json', 
 
      success: function(response){ 
 
       var itineraries = response.Itineraries; 
 
       var agents  = response.Agents; 
 
       var legs  = response.Legs; 
 
       var carriers = response.Carriers; 
 
       var places  = response.Places; 
 

 
       $.each(itineraries, function(itineraryKey, itineraryVal){ 
 
        var inbound   = app.getObjects(legs, 'Id', itineraryVal.InboundLegId), 
 
         inDepartureTime = inbound[0].Departure, 
 
         inArrivalTime = inbound[0].Arrival, 
 
         inDepartureDate = inbound[0].Departure, 
 
         inArrivalDate = inbound[0].Arrival, 
 
         inOrigin  = app.getObjects(places, 'Id', inbound[0].DestinationStation), 
 
         inDestination = app.getObjects(places, 'Id', inbound[0].OriginStation), 
 
         inCarriers  = app.getObjects(carriers, 'Id', inbound[0].OperatingCarriers[0]); 
 

 
        var outbound   = app.getObjects(legs, 'Id', itineraryVal.OutboundLegId), 
 
         outDepartureTime = outbound[0].Departure, 
 
         outArrivalTime = outbound[0].Arrival, 
 
         outDepartureDate = outbound[0].Departure, 
 
         outArrivalDate = outbound[0].Arrival, 
 
         outOrigin  = app.getObjects(places, 'Id', outbound[0].DestinationStation), 
 
         outDestination = app.getObjects(places, 'Id', outbound[0].OriginStation), 
 
         outCarriers  = app.getObjects(carriers, 'Id', outbound[0].OperatingCarriers[0]); 
 

 

 
        var agent  = app.getObjects(agents, 'Id', itineraryVal.PricingOptions[0].Agents[0]); 
 
        var price  = itineraryVal.PricingOptions[0].Price.toFixed(2); 
 
        var permalink = itineraryVal.PricingOptions[0].DeeplinkUrl; 
 
        var time  = itineraryVal.PricingOptions[0].QuoteAgeInMinutes; 
 

 
\t \t \t \t \t // NEW FORMAT OF DATA 
 
        var data = { 
 
         agent  : agent, 
 
         price  : price, 
 
         time  : time, 
 
         permalink : permalink, 
 
         inbound : { 
 
          time : { 
 
           departure : inDepartureTime, 
 
           arrival : inArrivalTime 
 
          }, 
 
          date : { 
 
           departure : inDepartureDate, 
 
           arrival : inArrivalDate 
 
          }, 
 
          station : { 
 
           origin  : inOrigin, 
 
           destination : inDestination 
 
          }, 
 
          carriers : inCarriers 
 
         }, 
 
         outbound : { 
 
          time : { 
 
           departure : outDepartureTime, 
 
           arrival : outArrivalTime 
 
          }, 
 
          date : { 
 
           departure : outDepartureDate, 
 
           arrival : outArrivalDate 
 
          }, 
 
          station : { 
 
           origin  : outOrigin, 
 
           destination : outDestination 
 
          }, 
 
          carriers : outCarriers 
 
         } 
 
        }; 
 
\t \t \t \t \t 
 
        // will display the NEW FORMAT OF DATA 
 
\t \t \t \t \t console.log(data); 
 
       }); 
 
      }, 
 
      error: function(error){ 
 
       console.log(error); 
 
      } 
 
     }); 
 
    }; 
 

 
\t app.displayData = function(data ) 
 
\t { 
 
\t \t console.log(data); 
 
\t }; 
 

 
    app.getObjects = function(obj, key, val) { 
 
     var objects = []; 
 
     for (var i in obj) { 
 
      if (!obj.hasOwnProperty(i)) continue; 
 
      if (typeof obj[i] == 'object') { 
 
       objects = objects.concat(app.getObjects(obj[i], key, val));  
 
      } else 
 
      //if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not) 
 
      if (i == key && obj[i] == val || i == key && val == '') { // 
 
       objects.push(obj); 
 
      } else if (obj[i] == val && key == ''){ 
 
       //only add if the object is not already in the array 
 
       if (objects.lastIndexOf(obj) == -1){ 
 
        objects.push(obj); 
 
       } 
 
      } 
 
     } 
 
     return objects; 
 
    }; 
 

 

 
    $(document).ready(app.init); 
 

 
    return app; 
 

 
})(window, document, jQuery); 
 

 
</script>

附:我希望這會幫助你瞭解如何獲得你需要的數據。

0

我將展示一個如何解析的基本示例。以下面的示例JSON。 http://api.androidhive.info/contacts/

如何獲取聯繫人列表。

JSONObject jsonObj = new JSONObject("Your JSON String here"); 
JSONArray contacts = jsonObj.optJSONArray("contacts"); 

如何計算的電話號碼

//Get first contact 


    JSONObject firstContact = contacts.optJSONObject(0); 
    JSONObject phone = firstContact.optJSONObject("phone"); 
    String mobileNo = phone.optString("mobile"); 

同樣可以將此技術應用到您的JSON。