1

これは単純なはずですが、明らかにトリックがありません。私はPOCOを持っています:

public class job
{
    public string title { get; set; }
    public string company { get; set; }
    public string companywebsite { get; set; }

    public string[] locations { get; set; }
}

RestSharp を使用して XML にシリアル化しています。私は次のいずれかを取得したいと考えています:

<job>
    <title>Hello title</title>
    <company>Hello company</company>
    <locations>New York</locations>
    <locations>Los Angeles</locations>
    <locations>Detroit</locations>
</job>

それとも理想...

<job>
    <title>Hello title</title>
    <company>Hello company</company>
    <locations>
         <location>New York</location>
         <location>Los Angeles</location>
         <location>Detroit</location>
    </locations>
</job>

しかし、代わりにこれを取得しています:

<job>
    <title>Hello title</title>
    <company>Hello company</company>
    <locations>
         <String />
         <String />
         <String />
    </locations>
</job>

明らかに、POCO は異なる必要があります。私に何ができる?

4

1 に答える 1

3

属性を使用して XmlSerializer の動作を変更する必要があります

public class job
{
    public string title { get; set; }
    public string company { get; set; }
    public string companywebsite { get; set; }
    [XmlArray("locations")]
    [XmlArrayItem("location")]
    public string[] locations { get; set; }
}
于 2012-02-22T21:43:12.713 に答える