簡體   English   中英

JSON序列化器C#

[英]JSON Serializer C#

我正在開發在線飛機銷售系統。

但是我有一個問題。

URL地址具有:

string urlFlightSearch = "https://api.iati.com/rest/flightSearch/" + ado.iatiKod + "";

在代碼中有類“ iati.cs”

public class iati
{
    public class flightSearch
    {
        public string fromAirport { get; set; }
        public bool allinFromCity { get; set; }
        public string toAirport { get; set; }
        public string fromDate { get; set; }
        public string returnDate { get; set; }
        public string adult { get; set; }
        public string currency { get; set; }
    }
    public class Leg
    {
        public string flightNo { get; set; }
        public string aircraft { get; set; }
        public string operatorCode { get; set; }
        public string operatorName { get; set; }
        public string departureAirport { get; set; }
        public string departureTime { get; set; }
        public string departureAirportName { get; set; }
        public string departureCityName { get; set; }
        public string arrivalAirport { get; set; }
        public string arrivalTime { get; set; }
        public string arrivalAirportName { get; set; }
        public string arrivalCityName { get; set; }
    }
    public class Detail
    {
        public double price { get; set; }
        public double serviceFee { get; set; }
        public double tax { get; set; }
        public int suplement { get; set; }
    }
    public class Fare
    {
        public double totalSingleAdultFare { get; set; }
        public string currency { get; set; }
        public string type { get; set; }
        public List<string> segmentNames { get; set; }
        public int freeSeatCount { get; set; }
        public Detail detail { get; set; }
    }
    public class Flight
    {
        public string id { get; set; }
        public string providerKey { get; set; }
        public string pricingType { get; set; }
        public int packageId { get; set; }
        public List<Leg> legs { get; set; }
        public List<Fare> fares { get; set; }
        public int segmentCount { get; set; }
        public int baggage { get; set; }
        public int flightTimeHour { get; set; }
        public int flightTimeMinute { get; set; }
        public int layoverTime { get; set; }
        public bool hasCip { get; set; }
        public bool canBook { get; set; }
        public bool canRezerve { get; set; }
        public bool dayCross { get; set; }
        public bool returnFlight { get; set; }
    }
    public class Result
    {
        public string searchId { get; set; }
        public List<Flight> flights { get; set; }
    }
    public class RootObject
    {
        public Result result { get; set; }
    }
}

並發布...

WebClient wc = new WebClient();
var serializer = new JavaScriptSerializer();

iati.flightSearch search = new iati.flightSearch()
{
    fromAirport = "IST",
    allinFromCity = true,
    toAirport = "AYT",
    fromDate = "2013-12-23",
    returnDate = "2013-12-30",
    adult = "1",
    currency = "EUR"
};

var serializedResult = serializer.Serialize(search);
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
string result = wc.UploadString(urlFlightSearch, serializedResult);
iati.Flight flight = serializer.Deserialize<iati.Flight>(result);

但是返回的結果總是空白。

在這里看到這張圖片

問候。

使用Newtonsoft

JsonConvert.DeserializeObject(結果);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM