有如下XML格式字符串:<Response>
<status>0</status>
<statusMessage>SUCCESS</statusMessage>
<productGroupList>
<productGroup>
<prdtGrpId>1981</prdtGrpId>
<prdtGrpType>EVENT</prdtGrpType>
<prdtGrpCode>jaychou0108</prdtGrpCode>
<prdtGrpName>周杰倫2008世界巡迴演唱會 Jay Chou World Tour 2008</prdtGrpName>
<prdtGrpKeyword></prdtGrpKeyword>
<prdtGrpGenre></prdtGrpGenre>
<prdtGrpPromoterName>Hype Records Pte Ltd</prdtGrpPromoterName>
<prdtGrpCreatedDate></prdtGrpCreatedDate>
<prdtGrpLastUpdatedDate></prdtGrpLastUpdatedDate>
<productIdList>
<productId>18011</productId>
<productId>18073</productId>
<productIdList>
</productGroup>
<productGroup>
<prdtGrpId>1864</prdtGrpId>
<prdtGrpType>EVENT</prdtGrpType>
<prdtGrpCode>amei1107</prdtGrpCode>
<prdtGrpName>A-Mei World Tour 2007</prdtGrpName>
<prdtGrpKeyword></prdtGrpKeyword>
<prdtGrpGenre></prdtGrpGenre>
<prdtGrpPromoterName>Unusual Entertainments Pte Ltd</prdtGrpPromoterName>
<prdtGrpCreatedDate></prdtGrpCreatedDate>
<prdtGrpLastUpdatedDate></prdtGrpLastUpdatedDate>
<productIdList>
<productId>18012</productId>
<productId>18072</productId>
<productIdList>
</productGroup>
</productGroupList>
</Response>我要把它反序列化为类,定义如下
[System.Xml.Serialization.XmlRoot("Response")]
[Serializable]
public class FetchProductResponse
{
/// <summary>
/// 卖方用户ID无法将类型
/// </summary>
[System.Xml.Serialization.XmlElement("status")]
public string status = string.Empty; /// <summary>
/// 卖方的身份验证,加密
/// </summary>
[System.Xml.Serialization.XmlElement("statusMessage")]
public string statusMessage = string.Empty;
/// <summary>
/// 返回结果
/// </summary>
[System.Xml.Serialization.XmlElement("productGroupList")]
public productGroupListResponse ProductResult = new productGroupListResponse(); }
[System.Xml.Serialization.XmlRoot("productGroupList")]
public class productGroupListResponse
{
[XmlArray("productGroupList")]
[XmlArrayItem("productGroup", typeof(productGroupResponse))]
public List<productGroupResponse> productGroupList = new List<productGroupResponse>();
}
[System.Xml.Serialization.XmlRoot("productGroup")]
[Serializable]
public class productGroupResponse
{
/// <summary>
/// 产品集团的唯一ID
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpId")]
public string prdtGrpId = string.Empty; /// <summary>
/// 产品组的类型
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpType")]
public string prdtGrpType = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpCode")]
public string prdtGrpCode = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpName")]
public string prdtGrpName = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpKeyword")]
public string prdtGrpKeyword = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpGenre")]
public string prdtGrpGenre = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpPromoterName")]
public string prdtGrpPromoterName = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpCreatedDate")]
public string prdtGrpCreatedDate = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpLastUpdatedDate")]
public string prdtGrpLastUpdatedDate = string.Empty; [System.Xml.Serialization.XmlElement("productIdList")]
public productIdListResponse productIdList = new productIdListResponse();
}
[System.Xml.Serialization.XmlRoot("productIdList")]
[Serializable]
public class productIdListResponse
{
[XmlArray("productIdList")]
[XmlArrayItem("productId", typeof(productInfo))]
public List<productInfo> IdList = new List<productInfo>();
}
[Serializable]
public class productInfo
{
/// <summary>
/// 产品ID
/// </summary>
[System.Xml.Serialization.XmlElement("productId")]
public string productId = string.Empty;
}请问这样定义对吗,如果有问题,麻烦各位帮我指正下,谢谢
<status>0</status>
<statusMessage>SUCCESS</statusMessage>
<productGroupList>
<productGroup>
<prdtGrpId>1981</prdtGrpId>
<prdtGrpType>EVENT</prdtGrpType>
<prdtGrpCode>jaychou0108</prdtGrpCode>
<prdtGrpName>周杰倫2008世界巡迴演唱會 Jay Chou World Tour 2008</prdtGrpName>
<prdtGrpKeyword></prdtGrpKeyword>
<prdtGrpGenre></prdtGrpGenre>
<prdtGrpPromoterName>Hype Records Pte Ltd</prdtGrpPromoterName>
<prdtGrpCreatedDate></prdtGrpCreatedDate>
<prdtGrpLastUpdatedDate></prdtGrpLastUpdatedDate>
<productIdList>
<productId>18011</productId>
<productId>18073</productId>
<productIdList>
</productGroup>
<productGroup>
<prdtGrpId>1864</prdtGrpId>
<prdtGrpType>EVENT</prdtGrpType>
<prdtGrpCode>amei1107</prdtGrpCode>
<prdtGrpName>A-Mei World Tour 2007</prdtGrpName>
<prdtGrpKeyword></prdtGrpKeyword>
<prdtGrpGenre></prdtGrpGenre>
<prdtGrpPromoterName>Unusual Entertainments Pte Ltd</prdtGrpPromoterName>
<prdtGrpCreatedDate></prdtGrpCreatedDate>
<prdtGrpLastUpdatedDate></prdtGrpLastUpdatedDate>
<productIdList>
<productId>18012</productId>
<productId>18072</productId>
<productIdList>
</productGroup>
</productGroupList>
</Response>我要把它反序列化为类,定义如下
[System.Xml.Serialization.XmlRoot("Response")]
[Serializable]
public class FetchProductResponse
{
/// <summary>
/// 卖方用户ID无法将类型
/// </summary>
[System.Xml.Serialization.XmlElement("status")]
public string status = string.Empty; /// <summary>
/// 卖方的身份验证,加密
/// </summary>
[System.Xml.Serialization.XmlElement("statusMessage")]
public string statusMessage = string.Empty;
/// <summary>
/// 返回结果
/// </summary>
[System.Xml.Serialization.XmlElement("productGroupList")]
public productGroupListResponse ProductResult = new productGroupListResponse(); }
[System.Xml.Serialization.XmlRoot("productGroupList")]
public class productGroupListResponse
{
[XmlArray("productGroupList")]
[XmlArrayItem("productGroup", typeof(productGroupResponse))]
public List<productGroupResponse> productGroupList = new List<productGroupResponse>();
}
[System.Xml.Serialization.XmlRoot("productGroup")]
[Serializable]
public class productGroupResponse
{
/// <summary>
/// 产品集团的唯一ID
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpId")]
public string prdtGrpId = string.Empty; /// <summary>
/// 产品组的类型
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpType")]
public string prdtGrpType = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpCode")]
public string prdtGrpCode = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpName")]
public string prdtGrpName = string.Empty; /// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpKeyword")]
public string prdtGrpKeyword = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpGenre")]
public string prdtGrpGenre = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpPromoterName")]
public string prdtGrpPromoterName = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpCreatedDate")]
public string prdtGrpCreatedDate = string.Empty;
/// <summary>
///
/// </summary>
[System.Xml.Serialization.XmlElement("prdtGrpLastUpdatedDate")]
public string prdtGrpLastUpdatedDate = string.Empty; [System.Xml.Serialization.XmlElement("productIdList")]
public productIdListResponse productIdList = new productIdListResponse();
}
[System.Xml.Serialization.XmlRoot("productIdList")]
[Serializable]
public class productIdListResponse
{
[XmlArray("productIdList")]
[XmlArrayItem("productId", typeof(productInfo))]
public List<productInfo> IdList = new List<productInfo>();
}
[Serializable]
public class productInfo
{
/// <summary>
/// 产品ID
/// </summary>
[System.Xml.Serialization.XmlElement("productId")]
public string productId = string.Empty;
}请问这样定义对吗,如果有问题,麻烦各位帮我指正下,谢谢
解决方案 »
- webbrowser获取窗体内的图片
- 求教《求一身份证正则表达式,要求能验证省市,出生年月,地区,位数》
- 写一个存储过程调用C#的dll文件
- 为什么我的DataGridView的ColumnIndex是乱的?
- 一个郁闷的正则问题
- 小弟做了一个console的程序,如何在做安装部署的时候把它包装成windows service.
- C#中有没有throws关键字,在线等
- FolderBrowserDialog怎么屏蔽鼠标右键?
- 如何才能让几个窗口必须包含某些控件
- current赋值错误在执行MoveNext时抛出
- 如何运用comboBox进行时间设定???帮帮忙吧!!
- C# 都进来看看吧, ------- IP连接打印机并打印,下面代码有问题 吗?谢谢
调整XmlElement
就可以了
你这不涉及attr
[Serializable]
public class productIdListResponse
{
[XmlArray("productIdList")]
[XmlArrayItem("productId", typeof(productInfo))]
public productInfo[] IdList ;
}
XmlSerializer 无法序列化或反序列化以下数组:
ArrayList 的数组,
List 的数组