gpt4 book ai didi

c# - 如何反序列化数组

转载 作者:太空宇宙 更新时间:2023-11-03 20:26:09 26 4
gpt4 key购买 nike

这是我从网站上得到的 Xml:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="[url]">
<totalResults>1</totalResults>
<movie code="134539" />
<movie code="134540" />
</feed>

我的 C# 类(class):

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

[Serializable]
[XmlRoot("feed", Namespace = "[url]")]
public class FeedSearch
{
[XmlElement("totalResults")]
public int TotalResults
{ get; set; }

[XmlArray("feed")]
[XmlArrayItem("movie")]
public List<MovieSearch> Movies
{ get; set; }
}

using System;
using System.Xml.Serialization;

[Serializable]
[XmlRoot("movie", Namespace = "[url]")]
public class MovieSearch
{
[XmlAttribute("code")]
public int Code
{ get; set; }
}

TotalResults 总是很好地反序列化,但我的电影列表总是空的,为什么?

最佳答案

代替:

[XmlArray("feed")]
[XmlArrayItem("movie")]
public List<MovieSearch> Movies { get; set; }

像这样尝试:

[XmlElement("movie")]
public List<MovieSearch> Movies { get; set; }

关于c# - 如何反序列化数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com