C# 反序列化 XML

yinqi025 2015-05-17 03:04:31
XML内容如下

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<BookRQ>
<AuthenticationToken>
<Username>taobao</Username>
<Password>taobao</Password>
<CreateToken>taobao13877840332631387784033266</CreateToken>
</AuthenticationToken>
<TaoBaoOrderId>1387784033263</TaoBaoOrderId>
</BookRQ>



我反序列化这个XML字符串 成BookRQ对象 这个AuthenticationToken属性的特性该怎么定义?

[Serializable]
public class BookRQ
{
/*****这里的XML不知道该如何定义? 有谁知道求救了 在线等****************
[XmlArrayItem(Type = typeof(string)), XmlArrayItem(Type = typeof(int)), XmlArrayItem(Type = typeof(string))]
public AuthenticationToken[] AuthenticationToken { get; set; }
**************/

[XmlElement]
public string TaoBaoOrderId { get; set; }
}

[Serializable]
public class AuthenticationToken
{
[XmlElement]
public string Username { get; set; }

[XmlElement]
public int Password { get; set; }

[XmlElement]
public string CreateToken { get; set; }
}


...全文
110 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinqi025 2015-05-17
  • 打赏
  • 举报
回复
引用 2 楼 x8bits 的回复:
很显然,你的Password属性要用string类型。
    [Serializable]
    public class BookRQ
    {
		[XmlElement]
 		public AuthenticationToken AuthenticationToken { get; set; }
 
        [XmlElement]
        public string TaoBaoOrderId { get; set; }
    }
 
    [Serializable]
    public class AuthenticationToken
    {
        [XmlElement]
        public string Username { get; set; }
 
        [XmlElement]
        public string Password { get; set; }
 
        [XmlElement]
        public string CreateToken { get; set; }
    }
自己已经解决 谢谢答应 这个密码这里我也是存在问题的 谢谢了 分就给你了
x8bits 2015-05-17
  • 打赏
  • 举报
回复
很显然,你的Password属性要用string类型。
    [Serializable]
    public class BookRQ
    {
		[XmlElement]
 		public AuthenticationToken AuthenticationToken { get; set; }
 
        [XmlElement]
        public string TaoBaoOrderId { get; set; }
    }
 
    [Serializable]
    public class AuthenticationToken
    {
        [XmlElement]
        public string Username { get; set; }
 
        [XmlElement]
        public string Password { get; set; }
 
        [XmlElement]
        public string CreateToken { get; set; }
    }
yinqi025 2015-05-17
  • 打赏
  • 举报
回复
自己顶一下

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧