无法在此XML响应中反序列化“MenuRespose”

时间:2017-08-17 05:36:40

标签: c# xml

我无法在此XML响应中反序列化MenuRespose

<LOGIN_REQUEST_RET>
<ERRMSG>Processed successfully.</ERRMSG>
<ERR_NUMBER>0</ERR_NUMBER>
<ERROR_FOUND>No</ERROR_FOUND>
<ProductID>1518</ProductID>
<MYCHOICE>1</MYCHOICE>
<MenuResponse>
  <SSMenus>
   <Mtemp>
      <ControlID>100</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Card Summary</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>101</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Card Summary</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>102</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Statement</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>103</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Recent Activity</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>104</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Alerts</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>105</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Lost/Stolen Card</SubMenuName>
      <IsChecked>1</IsChecked>
   </Mtemp>
   <Mtemp>
      <ControlID>106</ControlID>
      <MenuName>My Card</MenuName>
      <SubMenuName>Cardholder Agreement</SubMenuName>
      <IsChecked>0</IsChecked>
   </Mtemp>  
  </SSMenus>
</MenuResponse>
<ORIG_CURRENCY_CD/>
<CURR_DESC/>
<REMITTANCE_FLAG/>
<CLIENTID>1000</CLIENTID>
</LOGIN_REQUEST_RET>

要反序列化,我使用以下属性:

[XmlElement("MenuResponse ")]
public MenuResponse MenuResponse { get; set; }
[Serializable]
public class MenuResponse
{      
    public SSMenus SSMenus { get; set; }
}

public class SSMenus
{  
    public List<Mtemp> Mtemp { get; set; }
}

public class Mtemp
{
    [XmlElement("SKey")]
    public string SKey { get; set; }

    [XmlElement("ControlID")]
    public string ControlID { get; set; }

    [XmlElement("IsChecked")]
    public string IsChecked { get; set; }

    [XmlElement("LogoAcctid")]
    public string LogoAcctid { get; set; }

    [XmlElement("Menu")]
    public string Menu { get; set; }

    [XmlElement("SubMenu")]
    public string SubMenu { get; set; }
}

当我尝试反序列化输出时如下:

  

menuReponse:Count(0)

有人可以帮忙吗?我花了很多时间。

1 个答案:

答案 0 :(得分:0)

添加根类(如果还没有)

[Serializable]
[XmlRoot("LOGIN_REQUEST_RET")]
public class Response
{
    public MenuResponse MenuResponse { get; set; }
}

将MenuResponse更改为

[Serializable]
public class MenuResponse
{
    public List<Mtemp> SSMenus { get; set; }
}

删除SSMenus

使用xsd.exe从xml生成类