Я пытаюсь ввести данные json в модель.
Мой «flightSearchResult» возвращает значение null.
Я не уверен, но я бы сказал, что проблема в дезерализации или моя модель не очень хорошая.
Формат Json действителен, как я вижу в терминале, и статус 200 ОК.
var url = $"/v2/shopping/flight-offers?originLocationCode={originLocationCode}&destinationLocationCode={destinationLocationCode}&departureDate={departureDate}&returnDate={returnDate}&adults={adults}¤cyCode={currencyCode}";
var message = new HttpRequestMessage(HttpMethod.Get, url);
var response = await http.SendAsync(message);
response.EnsureSuccessStatusCode();
using var stream = await response.Content.ReadAsStreamAsync();
var rawResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Raw API Response: {rawResponse}");
// Deserialize the API response into the model
var flightSearchResult = await JsonSerializer.DeserializeAsync(stream);
public class FlightSearchResult
{
public List Data { get; set; }
}
public class FlightOffer
{
public string Type { get; set; }
public string Id { get; set; }
public string Source { get; set; }
public bool InstantTicketingRequired { get; set; }
public bool NonHomogeneous { get; set; }
public bool OneWay { get; set; }
public bool IsUpsellOffer { get; set; }
public string LastTicketingDate { get; set; }
public string LastTicketingDateTime { get; set; }
public int NumberOfBookableSeats { get; set; }
public List Itineraries { get; set; }
public Price Price { get; set; }
public PricingOptions PricingOptions { get; set; }
public List ValidatingAirlineCodes { get; set; }
public List TravelerPricings { get; set; }
}
public class Itinerary
{
public string Duration { get; set; }
public List Segments { get; set; }
}
public class Segment
{
public Departure Arrival { get; set; }
public Departure Departure { get; set; }
public string CarrierCode { get; set; }
public string Number { get; set; }
public Aircraft Aircraft { get; set; }
public Operating Operating { get; set; }
public string Duration { get; set; }
public string Id { get; set; }
public int NumberOfStops { get; set; }
public bool BlacklistedInEU { get; set; }
}
public class Departure
{
public string IataCode { get; set; }
public string Terminal { get; set; }
public string At { get; set; }
}
public class Aircraft
{
public string Code { get; set; }
}
public class Operating
{
public string CarrierCode { get; set; }
}
public class Price
{
public string Currency { get; set; }
public string Total { get; set; }
public string Base { get; set; }
public List Fees { get; set; }
public string GrandTotal { get; set; }
}
public class Fee
{
public string Amount { get; set; }
public string Type { get; set; }
}
public class PricingOptions
{
public List FareType { get; set; }
public bool IncludedCheckedBagsOnly { get; set; }
}
public class TravelerPricing
{
public string TravelerId { get; set; }
public string FareOption { get; set; }
public string TravelerType { get; set; }
public Price Price { get; set; }
public List FareDetailsBySegment { get; set; }
}
public class FareDetail
{
public string SegmentId { get; set; }
public string Cabin { get; set; }
public string FareBasis { get; set; }
public string Class { get; set; }
public IncludedCheckedBags IncludedCheckedBags { get; set; }
}
public class IncludedCheckedBags
{
public int Weight { get; set; }
public string WeightUnit { get; set; }
}
Я пытаюсь ввести данные json в модель. Мой «flightSearchResult» возвращает значение null. Я не уверен, но я бы сказал, что проблема в дезерализации или моя модель не очень хорошая. Формат Json действителен, как я вижу в терминале, и статус 200 ОК. [code]var url = $"/v2/shopping/flight-offers?originLocationCode={originLocationCode}&destinationLocationCode={destinationLocationCode}&departureDate={departureDate}&returnDate={returnDate}&adults={adults}¤cyCode={currencyCode}"; var message = new HttpRequestMessage(HttpMethod.Get, url);
var response = await http.SendAsync(message);
response.EnsureSuccessStatusCode();
using var stream = await response.Content.ReadAsStreamAsync();
var rawResponse = await response.Content.ReadAsStringAsync(); Console.WriteLine($"Raw API Response: {rawResponse}");
// Deserialize the API response into the model
var flightSearchResult = await JsonSerializer.DeserializeAsync(stream); [/code] Модель FlightSearchResult [code]public class FlightSearchResult { public List Data { get; set; } }
public class FlightOffer { public string Type { get; set; } public string Id { get; set; } public string Source { get; set; } public bool InstantTicketingRequired { get; set; } public bool NonHomogeneous { get; set; } public bool OneWay { get; set; } public bool IsUpsellOffer { get; set; } public string LastTicketingDate { get; set; } public string LastTicketingDateTime { get; set; } public int NumberOfBookableSeats { get; set; } public List Itineraries { get; set; } public Price Price { get; set; } public PricingOptions PricingOptions { get; set; } public List ValidatingAirlineCodes { get; set; } public List TravelerPricings { get; set; } }
public class Itinerary { public string Duration { get; set; } public List Segments { get; set; } }
public class Segment { public Departure Arrival { get; set; } public Departure Departure { get; set; } public string CarrierCode { get; set; } public string Number { get; set; } public Aircraft Aircraft { get; set; } public Operating Operating { get; set; } public string Duration { get; set; } public string Id { get; set; } public int NumberOfStops { get; set; } public bool BlacklistedInEU { get; set; } }
public class Departure { public string IataCode { get; set; } public string Terminal { get; set; } public string At { get; set; } }
public class Aircraft { public string Code { get; set; } }
public class Operating { public string CarrierCode { get; set; } }
public class Price { public string Currency { get; set; } public string Total { get; set; } public string Base { get; set; } public List Fees { get; set; } public string GrandTotal { get; set; } }
public class Fee { public string Amount { get; set; } public string Type { get; set; } }
public class PricingOptions { public List FareType { get; set; } public bool IncludedCheckedBagsOnly { get; set; } }
public class TravelerPricing { public string TravelerId { get; set; } public string FareOption { get; set; } public string TravelerType { get; set; } public Price Price { get; set; } public List FareDetailsBySegment { get; set; } }
public class FareDetail { public string SegmentId { get; set; } public string Cabin { get; set; } public string FareBasis { get; set; } public string Class { get; set; } public IncludedCheckedBags IncludedCheckedBags { get; set; } }
public class IncludedCheckedBags { public int Weight { get; set; } public string WeightUnit { get; set; } } [/code]