关于XML转实体类

caiyi000 caiyi000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
谁能帮我把以下XML转成实体类呢?

<?xml version="1.0" encoding="utf-8"?>
<response>
<functionID>abc</functionID>
<totalInfo>
<itemsCount>3</itemsCount>
</totalInfo>
<ItemsList>
<ItemInfo>
<itemName>aaaaa</itemName>
<itemPrice>10</itemPrice>
<ItemInfo/>
<ItemInfo>
<itemName>bbbbb</itemName>
<itemPrice>20</itemPrice>
<ItemInfo/>
</ItemsList>
</response>



public static T DeserializeXML<T>(string pmXMLString) {

XmlSerializer xs = new XmlSerializer(typeof(T));
T tObjext = (T)xs.Deserialize(new StringReader(pmXMLString));
return tObjext;
}



public class response
{
/// <summary>
/// 方法名称
/// </summary>
public string functionID { get; set; }

public totalInfo totalInfo { get; set; }

public ItemsList ItemsList { get; set; }
}

public class totalInfo
{
/// <summary>
/// 产品数量
/// </summary>
public int itemsCount { get; set; }

}

public class ItemsList
{
public List<ItemInfo> ItemInfo
{
set;
get;
}
}

public class ItemInfo
{

public string itemName{ get; set; }

public string itemPrice{ get; set; }
}

var a=DeserializeXML<response>(xmlstring);

我用XmlSerializer方法不行。。ItemsList老实取不到
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
caiyi000
C# 111,129 成员 642,540 内容