【发布时间】:2021-05-18 02:39:28
【问题描述】:
我有以下 XML -
类结构->
public class AvailabilityResponse
{
public string property_id { get; set; }
public List<AvailRoom> rooms { get; set; }
public Links links { get; set; }
public int score { get; set; }
public string Type { get; set; }
public string Message { get; set; }
public string status { get; set; }
}
public class AvailRoom
{
public string id { get; set; }
public string room_name { get; set; }
public List<AvailRate> rates { get; set; }
}
[Serializable]
public class AvailRate
{
public string id { get; set; }
public int available_rooms { get; set; }
public bool refundable { get; set; }
public bool fenced_deal { get; set; }
public bool fenced_deal_available { get; set; }
public bool deposit_required { get; set; }
public string merchant_of_record { get; set; }
public List<Amenity> amenities { get; set; }
public Links links { get; set; }
//[XmlElement(ElementName = "bed_groups")]
//public List<BedGroups> bed_groups { get; set; }
[XmlElement(ElementName = "bed_groups")]
public List<BedGroup> bed_groups { get; set; }
public List<CancelPenalty> cancel_penalties { get; set; }
public Dictionary<string, occupancy_pricing> occupancy_pricing { get; set; }
public occupancy_pricing Occupancy { get; set; }
}
public class BedGroup
{
public Links links { get; set; }
public List<Configuration> configuration { get; set; }
}
[Serializable]
public class Links
{
public PaymentOptions payment_options { get; set; }
public Book book { get; set; }
public PriceCheck price_check { get; set; }
public AdditionalRates additional_rates { get; set; }
public Retrieve retrieve { get; set; }
public Cancel cancel { get; set; }
public Change change { get; set; }
public string method { get; set; }
public string href { get; set; }
}
[Serializable]
public class PriceCheck
{
public string method { get; set; }
public string href { get; set; }
}
结构的问题是,除了bed_groups,所有其他元素都被绑定了。
我尝试了不同的条件,比如用 Visual Studio 序列化 xml 类,用不同的标签注释它们。但这没有用。
例如。 cancel_penalties 具有类似的结构,但它正确绑定到 c# 类。 bed_groups 没有被绑定。每次它都为空,尽管值存在于 xml 中。
是因为 - <a:item xmlns:a="item" item="37316" type="object"> in bed_groups 和其他标签它只有 - <item type="object"> 吗?
有什么办法可以解决这个问题?
【问题讨论】:
标签: c# .net xml serialization