gpt4 book ai didi

json - Flutter从Rest API解析.JSON

转载 作者:行者123 更新时间:2023-12-03 04:57:55 26 4
gpt4 key购买 nike

我需要从在线API解析Json对象的帮助。
我是新手,但我不太了解如何解决这个问题,而且似乎没有很多在线资源。

JSON如下所示:

{ "data": [ { "type": "flight-destination", "origin": "MAD", "destination": "LON", "departureDate": "2020-03-11", "returnDate": "2020-03-14", "price": { "total": "80.55" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=LON&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=LON&departureDate=2020-03-11&returnDate=2020-03-14&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "ALC", "departureDate": "2020-03-23", "returnDate": "2020-03-28", "price": { "total": "87.29" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=ALC&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=ALC&departureDate=2020-03-23&returnDate=2020-03-28&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "GOA", "departureDate": "2020-02-27", "returnDate": "2020-03-12", "price": { "total": "99.96" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=GOA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=GOA&departureDate=2020-02-27&returnDate=2020-03-12&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MUC", "departureDate": "2020-03-23", "returnDate": "2020-03-29", "price": { "total": "120.58" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MUC&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MUC&departureDate=2020-03-23&returnDate=2020-03-29&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "VCE", "departureDate": "2020-04-14", "returnDate": "2020-04-28", "price": { "total": "125.92" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=VCE&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=VCE&departureDate=2020-04-14&returnDate=2020-04-28&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "GOT", "departureDate": "2020-03-15", "returnDate": "2020-03-19", "price": { "total": "134.99" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=GOT&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=GOT&departureDate=2020-03-15&returnDate=2020-03-19&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "VIE", "departureDate": "2020-02-29", "returnDate": "2020-03-01", "price": { "total": "135.72" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=VIE&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=VIE&departureDate=2020-02-29&returnDate=2020-03-01&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "TUN", "departureDate": "2020-04-09", "returnDate": "2020-04-13", "price": { "total": "139.01" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=TUN&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=TUN&departureDate=2020-04-09&returnDate=2020-04-13&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "KRK", "departureDate": "2020-05-11", "returnDate": "2020-05-13", "price": { "total": "142.34" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=KRK&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=KRK&departureDate=2020-05-11&returnDate=2020-05-13&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "WAW", "departureDate": "2020-03-11", "returnDate": "2020-03-15", "price": { "total": "143.66" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=WAW&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=WAW&departureDate=2020-03-11&returnDate=2020-03-15&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "PSA", "departureDate": "2020-03-04", "returnDate": "2020-03-07", "price": { "total": "145.61" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=PSA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=PSA&departureDate=2020-03-04&returnDate=2020-03-07&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "DBV", "departureDate": "2020-03-23", "returnDate": "2020-03-26", "price": { "total": "156.53" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=DBV&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=DBV&departureDate=2020-03-23&returnDate=2020-03-26&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "GLA", "departureDate": "2020-03-25", "returnDate": "2020-04-07", "price": { "total": "163.70" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=GLA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=GLA&departureDate=2020-03-25&returnDate=2020-04-07&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "LWO", "departureDate": "2020-04-14", "returnDate": "2020-04-17", "price": { "total": "164.20" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=LWO&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=LWO&departureDate=2020-04-14&returnDate=2020-04-17&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MOW", "departureDate": "2020-03-31", "returnDate": "2020-04-05", "price": { "total": "172.70" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MOW&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MOW&departureDate=2020-03-31&returnDate=2020-04-05&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "TLL", "departureDate": "2020-03-06", "returnDate": "2020-03-13", "price": { "total": "177.03" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=TLL&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=TLL&departureDate=2020-03-06&returnDate=2020-03-13&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "REK", "departureDate": "2020-03-23", "returnDate": "2020-03-27", "price": { "total": "184.74" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=REK&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=REK&departureDate=2020-03-23&returnDate=2020-03-27&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "RIX", "departureDate": "2020-03-06", "returnDate": "2020-03-13", "price": { "total": "197.33" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=RIX&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=RIX&departureDate=2020-03-06&returnDate=2020-03-13&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "CLJ", "departureDate": "2020-03-24", "returnDate": "2020-03-28", "price": { "total": "198.35" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=CLJ&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=CLJ&departureDate=2020-03-24&returnDate=2020-03-28&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "KIV", "departureDate": "2020-03-26", "returnDate": "2020-03-28", "price": { "total": "201.50" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=KIV&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=KIV&departureDate=2020-03-26&returnDate=2020-03-28&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "BOS", "departureDate": "2020-03-07", "returnDate": "2020-03-08", "price": { "total": "268.45" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=BOS&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=BOS&departureDate=2020-03-07&returnDate=2020-03-08&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "ORL", "departureDate": "2020-03-17", "returnDate": "2020-03-18", "price": { "total": "298.93" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=ORL&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=ORL&departureDate=2020-03-17&returnDate=2020-03-18&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "FLL", "departureDate": "2020-03-16", "returnDate": "2020-03-17", "price": { "total": "341.61" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=FLL&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=FLL&departureDate=2020-03-16&returnDate=2020-03-17&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "ACC", "departureDate": "2020-04-10", "returnDate": "2020-04-12", "price": { "total": "383.57" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=ACC&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=ACC&departureDate=2020-04-10&returnDate=2020-04-12&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "SLC", "departureDate": "2020-03-31", "returnDate": "2020-04-01", "price": { "total": "394.93" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=SLC&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=SLC&departureDate=2020-03-31&returnDate=2020-04-01&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "KTM", "departureDate": "2020-05-01", "returnDate": "2020-05-14", "price": { "total": "448.03" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=KTM&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=KTM&departureDate=2020-05-01&returnDate=2020-05-14&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "SEA", "departureDate": "2020-03-05", "returnDate": "2020-03-10", "price": { "total": "463.85" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=SEA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=SEA&departureDate=2020-03-05&returnDate=2020-03-10&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "SIN", "departureDate": "2020-04-30", "returnDate": "2020-05-04", "price": { "total": "482.40" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=SIN&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=SIN&departureDate=2020-04-30&returnDate=2020-05-04&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "PTY", "departureDate": "2020-03-09", "returnDate": "2020-03-19", "price": { "total": "484.95" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=PTY&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=PTY&departureDate=2020-03-09&returnDate=2020-03-19&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "TYO", "departureDate": "2020-03-22", "returnDate": "2020-03-24", "price": { "total": "499.24" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=TYO&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=TYO&departureDate=2020-03-22&returnDate=2020-03-24&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "SSA", "departureDate": "2020-03-24", "returnDate": "2020-04-08", "price": { "total": "506.02" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=SSA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=SSA&departureDate=2020-03-24&returnDate=2020-04-08&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "CCS", "departureDate": "2020-02-28", "returnDate": "2020-03-10", "price": { "total": "510.19" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=CCS&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=CCS&departureDate=2020-02-28&returnDate=2020-03-10&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MGA", "departureDate": "2020-04-01", "returnDate": "2020-04-12", "price": { "total": "514.39" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MGA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MGA&departureDate=2020-04-01&returnDate=2020-04-12&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "RGN", "departureDate": "2020-03-10", "returnDate": "2020-03-15", "price": { "total": "528.17" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=RGN&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=RGN&departureDate=2020-03-10&returnDate=2020-03-15&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "OSA", "departureDate": "2020-04-10", "returnDate": "2020-04-16", "price": { "total": "531.45" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=OSA&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=OSA&departureDate=2020-04-10&returnDate=2020-04-16&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "DEN", "departureDate": "2020-03-06", "returnDate": "2020-03-11", "price": { "total": "542.62" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=DEN&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=DEN&departureDate=2020-03-06&returnDate=2020-03-11&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MDZ", "departureDate": "2020-05-18", "returnDate": "2020-06-02", "price": { "total": "579.67" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MDZ&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MDZ&departureDate=2020-05-18&returnDate=2020-06-02&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MTY", "departureDate": "2020-04-02", "returnDate": "2020-04-10", "price": { "total": "612.22" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MTY&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MTY&departureDate=2020-04-02&returnDate=2020-04-10&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "MLE", "departureDate": "2020-03-22", "returnDate": "2020-03-27", "price": { "total": "627.81" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=MLE&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=MLE&departureDate=2020-03-22&returnDate=2020-03-27&adults=1&nonStop=false" } }, { "type": "flight-destination", "origin": "MAD", "destination": "HNL", "departureDate": "2020-04-01", "returnDate": "2020-04-04", "price": { "total": "1283.29" }, "links": { "flightDates": "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MAD&destination=HNL&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DURATION", "flightOffers": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAD&destinationLocationCode=HNL&departureDate=2020-04-01&returnDate=2020-04-04&adults=1&nonStop=false" } } ], "dictionaries": { "currencies": { "EUR": "EURO" }, "locations": { "CLJ": { "subType": "AIRPORT", "detailedName": "CLUJ NAPOCA" }, "RIX": { "subType": "AIRPORT", "detailedName": "RIGA INTL" }, "KTM": { "subType": "AIRPORT", "detailedName": "TRIBHUVAN INTL" }, "KRK": { "subType": "AIRPORT", "detailedName": "JOHN PAUL II BALICE" }, "HNL": { "subType": "AIRPORT", "detailedName": "DANIEL K INOUYE INTL" }, "MLE": { "subType": "AIRPORT", "detailedName": "VELANA INTERNATIONAL" }, "FLL": { "subType": "AIRPORT", "detailedName": "FLL INTL" }, "ORL": { "subType": "AIRPORT", "detailedName": "EXECUTIVE" }, "SLC": { "subType": "AIRPORT", "detailedName": "SALT LAKE CITY INTL" }, "WAW": { "subType": "AIRPORT", "detailedName": "FREDERIC CHOPIN" }, "MTY": { "subType": "AIRPORT", "detailedName": "MARIANO ESCOBEDO INTL" }, "PTY": { "subType": "AIRPORT", "detailedName": "TOCUMEN INTL" }, "TLL": { "subType": "AIRPORT", "detailedName": "LENNART MERI" }, "GOA": { "subType": "AIRPORT", "detailedName": "CRISTOFORO COLOMBO" }, "DBV": { "subType": "AIRPORT", "detailedName": "DUBROVNIK" }, "MUC": { "subType": "AIRPORT", "detailedName": "MUNICH INTERNATIONAL" }, "OSA": { "subType": "CITY", "detailedName": "OSAKA" }, "PSA": { "subType": "AIRPORT", "detailedName": "GALILEO GALILEI" }, "SSA": { "subType": "AIRPORT", "detailedName": "D.L.E.MAGALHAES" }, "ACC": { "subType": "AIRPORT", "detailedName": "KOTOKA INTL" }, "MDZ": { "subType": "AIRPORT", "detailedName": "EL PLUMERILLO" }, "LWO": { "subType": "AIRPORT", "detailedName": "INTERNATIONAL" }, "MGA": { "subType": "AIRPORT", "detailedName": "AUGUSTO C.SANDINO INT" }, "BOS": { "subType": "AIRPORT", "detailedName": "EDWARD L LOGAN INTL" }, "LON": { "subType": "CITY", "detailedName": "LONDON" }, "TYO": { "subType": "CITY", "detailedName": "TOKYO" }, "DEN": { "subType": "AIRPORT", "detailedName": "DENVER INTERNATIONAL" }, "TUN": { "subType": "AIRPORT", "detailedName": "CARTHAGE" }, "GOT": { "subType": "AIRPORT", "detailedName": "LANDVETTER" }, "SEA": { "subType": "AIRPORT", "detailedName": "SEATTLE TACOMA INTL" }, "MAD": { "subType": "AIRPORT", "detailedName": "ADOLFO SUAREZ BARAJAS" }, "CCS": { "subType": "AIRPORT", "detailedName": "SIMON BOLIVAR INTL" }, "VIE": { "subType": "AIRPORT", "detailedName": "VIENNA INTERNATIONAL" }, "MOW": { "subType": "CITY", "detailedName": "MOSCOW" }, "RGN": { "subType": "AIRPORT", "detailedName": "MINGALADON" }, "ALC": { "subType": "AIRPORT", "detailedName": "ALICANTE AIRPORT" }, "KIV": { "subType": "AIRPORT", "detailedName": "INTERNATIONAL" }, "VCE": { "subType": "AIRPORT", "detailedName": "MARCO POLO" }, "REK": { "subType": "CITY", "detailedName": "REYKJAVIK" }, "SIN": { "subType": "AIRPORT", "detailedName": "CHANGI" }, "GLA": { "subType": "AIRPORT", "detailedName": "GLASGOW INTL" } } }, "meta": { "currency": "EUR", "links": { "self": "https://test.api.amadeus.com/v1/shopping/flight-destinations?origin=MAD&departureDate=2020-02-16,2020-08-13&oneWay=false&duration=1,15&nonStop=false&viewBy=DESTINATION" }, "defaults": { "departureDate": "2020-02-16,2020-08-13", "oneWay": false, "duration": "1,15", "nonStop": false, "viewBy": "DESTINATION" } } }

我已经写了这些类(class),但是我不知道下一步该怎么做:
class Price {
final String total;

Price({this.total});

factory Price.fromJson(Map<String, dynamic> json) {
return Price(
total: json['total'],
);
}
}
class Links {
final String flightDates;
final String flightOffers;

Links({this.flightDates, this.flightOffers});

factory Links.fromJson(Map<String, dynamic> json) {
return Links(
flightDates: json['flightDates'],
flightOffers: json['flightOffers'],
);
}
}
class Data {
final String type;
final String origin;
final String destination;
final String departureDate;
final String returnDate;
final Price price;
final Links links;

Data({this.type, this.origin,this.destination,this.departureDate,this.returnDate,this.price,this.links});

factory Data.fromJson(Map<String, dynamic> parsedJson) {
return Data(
type: parsedJson['type'],
origin: parsedJson['origin'],
destination: parsedJson['destination'],
departureDate: parsedJson['departureDate'],
returnDate: parsedJson['returnDate'],
price: Price.fromJson(parsedJson['price'],),
links: Links.fromJson(parsedJson['links'],));}}

class Links2 {
final String total;

Links2({this.total});

factory Links2.fromJson(Map<String, dynamic> json) {
return Links2(
total: json['self'],
);
}
}
class Default {
final String departureDate;
final bool oneWay;
final String duration;
final bool nonStop;
final String viewBy;

Default({this.departureDate, this.oneWay,this.duration,this.nonStop,this.viewBy,});

factory Default.fromJson(Map<String, dynamic> parsedJson) {
return Default(
departureDate: parsedJson['departureDate'],
oneWay: parsedJson['oneWay'],
duration: parsedJson['duration'],
nonStop: parsedJson['nonStop'],
viewBy: parsedJson['viewBy'],
);}}
class Meta {
final String currency;
final Links2 links2;
final Default defaults;

Meta(
{this.currency, this.links2, this.defaults});

factory Meta.fromJson(Map<String, dynamic> json) {
return Meta(
currency: json['currency'],
links2: Links2.fromJson(json['links']),
defaults: Default.fromJson(json['defaults']),
);
}
}


class All {
final List<Data> data;
final Meta meta;

All(
{this.data, this.meta});
static List<Data> parseData(dataJson) {
var list = dataJson['data'] as List;
List<Data> dataList =
list.map((data) => Data.fromJson(data)).toList();
return dataList;
}
factory All.fromJson(Map<String, dynamic> json) {
return All(
meta: Meta.fromJson(json['meta'],),
data: parseData(json),
);
}
}


Future<String> loadAllFromAssets() async {
return await rootBundle.loadString('json/all.json');
}

Future loadAll() async {
String jsonString = await loadAllFromAssets();
final jsonResponse = json.decode(jsonString);
All all = new All.fromJson(jsonResponse);
print('Images: ${all.data[0].type}');
}


还需要全部解析吗?或者有没有办法只使用数据。

最佳答案

有一个名为:QuickType.io的网站链接:https://app.quicktype.io
因此,根据您的json,我制作了一个如下所示的模型:

// To parse this JSON data, do
//
// final data = dataFromJson(jsonString);

import 'dart:convert';

Data dataFromJson(String str) => Data.fromJson(json.decode(str));

String dataToJson(Data data) => json.encode(data.toJson());

class Data {
List<Datum> data;
Dictionaries dictionaries;
Meta meta;

Data({
this.data,
this.dictionaries,
this.meta,
});

factory Data.fromJson(Map<String, dynamic> json) => Data(
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
dictionaries: Dictionaries.fromJson(json["dictionaries"]),
meta: Meta.fromJson(json["meta"]),
);

Map<String, dynamic> toJson() => {
"data": List<dynamic>.from(data.map((x) => x.toJson())),
"dictionaries": dictionaries.toJson(),
"meta": meta.toJson(),
};
}

class Datum {
Type type;
Origin origin;
String destination;
DateTime departureDate;
DateTime returnDate;
Price price;
DatumLinks links;

Datum({
this.type,
this.origin,
this.destination,
this.departureDate,
this.returnDate,
this.price,
this.links,
});

factory Datum.fromJson(Map<String, dynamic> json) => Datum(
type: typeValues.map[json["type"]],
origin: originValues.map[json["origin"]],
destination: json["destination"],
departureDate: DateTime.parse(json["departureDate"]),
returnDate: DateTime.parse(json["returnDate"]),
price: Price.fromJson(json["price"]),
links: DatumLinks.fromJson(json["links"]),
);

Map<String, dynamic> toJson() => {
"type": typeValues.reverse[type],
"origin": originValues.reverse[origin],
"destination": destination,
"departureDate": "${departureDate.year.toString().padLeft(4, '0')}-${departureDate.month.toString().padLeft(2, '0')}-${departureDate.day.toString().padLeft(2, '0')}",
"returnDate": "${returnDate.year.toString().padLeft(4, '0')}-${returnDate.month.toString().padLeft(2, '0')}-${returnDate.day.toString().padLeft(2, '0')}",
"price": price.toJson(),
"links": links.toJson(),
};
}

class DatumLinks {
String flightDates;
String flightOffers;

DatumLinks({
this.flightDates,
this.flightOffers,
});

factory DatumLinks.fromJson(Map<String, dynamic> json) => DatumLinks(
flightDates: json["flightDates"],
flightOffers: json["flightOffers"],
);

Map<String, dynamic> toJson() => {
"flightDates": flightDates,
"flightOffers": flightOffers,
};
}

enum Origin { MAD }

final originValues = EnumValues({
"MAD": Origin.MAD
});

class Price {
String total;

Price({
this.total,
});

factory Price.fromJson(Map<String, dynamic> json) => Price(
total: json["total"],
);

Map<String, dynamic> toJson() => {
"total": total,
};
}

enum Type { FLIGHT_DESTINATION }

final typeValues = EnumValues({
"flight-destination": Type.FLIGHT_DESTINATION
});

class Dictionaries {
Currencies currencies;
Map<String, Location> locations;

Dictionaries({
this.currencies,
this.locations,
});

factory Dictionaries.fromJson(Map<String, dynamic> json) => Dictionaries(
currencies: Currencies.fromJson(json["currencies"]),
locations: Map.from(json["locations"]).map((k, v) => MapEntry<String, Location>(k, Location.fromJson(v))),
);

Map<String, dynamic> toJson() => {
"currencies": currencies.toJson(),
"locations": Map.from(locations).map((k, v) => MapEntry<String, dynamic>(k, v.toJson())),
};
}

class Currencies {
String eur;

Currencies({
this.eur,
});

factory Currencies.fromJson(Map<String, dynamic> json) => Currencies(
eur: json["EUR"],
);

Map<String, dynamic> toJson() => {
"EUR": eur,
};
}

class Location {
SubType subType;
String detailedName;

Location({
this.subType,
this.detailedName,
});

factory Location.fromJson(Map<String, dynamic> json) => Location(
subType: subTypeValues.map[json["subType"]],
detailedName: json["detailedName"],
);

Map<String, dynamic> toJson() => {
"subType": subTypeValues.reverse[subType],
"detailedName": detailedName,
};
}

enum SubType { AIRPORT, CITY }

final subTypeValues = EnumValues({
"AIRPORT": SubType.AIRPORT,
"CITY": SubType.CITY
});

class Meta {
String currency;
MetaLinks links;
Defaults defaults;

Meta({
this.currency,
this.links,
this.defaults,
});

factory Meta.fromJson(Map<String, dynamic> json) => Meta(
currency: json["currency"],
links: MetaLinks.fromJson(json["links"]),
defaults: Defaults.fromJson(json["defaults"]),
);

Map<String, dynamic> toJson() => {
"currency": currency,
"links": links.toJson(),
"defaults": defaults.toJson(),
};
}

class Defaults {
String departureDate;
bool oneWay;
String duration;
bool nonStop;
String viewBy;

Defaults({
this.departureDate,
this.oneWay,
this.duration,
this.nonStop,
this.viewBy,
});

factory Defaults.fromJson(Map<String, dynamic> json) => Defaults(
departureDate: json["departureDate"],
oneWay: json["oneWay"],
duration: json["duration"],
nonStop: json["nonStop"],
viewBy: json["viewBy"],
);

Map<String, dynamic> toJson() => {
"departureDate": departureDate,
"oneWay": oneWay,
"duration": duration,
"nonStop": nonStop,
"viewBy": viewBy,
};
}

class MetaLinks {
String self;

MetaLinks({
this.self,
});

factory MetaLinks.fromJson(Map<String, dynamic> json) => MetaLinks(
self: json["self"],
);

Map<String, dynamic> toJson() => {
"self": self,
};
}

class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;

EnumValues(this.map);

Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}

关于json - Flutter从Rest API解析.JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60243327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com