How can I deserialize Xml list using Restsharp?

时光怂恿深爱的人放手 提交于 2019-11-30 07:10:37

It should work if you rename the Account class to Item and use Execute<List<Item>>(request). You don't need to specify a RootElement value.

Not sure what's wrong, but I'm sure John will be by soon to let you know :-) In the meanwhile, why not just do it the manual way:

    var root = XElement.Parse(xmlString);
    var accounts = from it in root.Element("xml").Elements("item")
                   select new Account() {
                                            AccountId = it.Element("accountid").Value,
                                            AccountTypeId = it.Element("accounttypeid").Value,
                                            AccountTypeName = it.Element("accounttypename").Value,
                                            AccountBankId = it.Element("banktypeid").Value,
                                            AccountBankName = it.Element("banktypename").Value,
                                            AccountSaldo = it.Element("accountsaldo").Value
                                        };

It's so clean and easy with XLinq. By adding a few extension methods to XElement you can make it even cleaner and resilient to missing elements/attributes.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!