2016-11-07 6 views
0

他のオブジェクトのリストを含むオブジェクトのリストを逆シリアル化しようとしています。私が持っているものは次のとおりです。 実際のデシリアライズは、ApiContoller httpPost要求のフレームワークによって行われます。エンドポイントは次のようになります。xml Cのオブジェクトのリストを含むオブジェクトのリストを逆シリアル化する#

[HttpPost] 
    public async Task<HttpResponseMessage> MethodCall([FromBody] XmlEntries entries) 
    { 
    .... 
    } 

XmlEntriesクラスは次のようになります。

[XmlRoot("Root")] 
public class XmlEntries 
{ 
    [XmlArrayItem("XmlEntry")] 
    public List<XmlEntry> XmlEntries{ get; set; } 

    public XmlEntries() 
    { 
     XmlEntries = new List<XmlEntry>(); 
    } 

    public XmlEntries(IEnumerable<XmlEntry> entries) 
    { 
     XmlEntries= entries.ToList(); 
    } 
} 

このようなXmlEntryクラスを見て:

public class XmlEntry 
{ 
    [XmlArrayItem("XmlSubEntry")] 
    public List<XmlSubEntry> XmlSubEntries{ get; set; } 
} 

とXmlSubEntryは次のようになります。

public class XmlSubEntry 
{ 
    string AttributeOne{ get; set; } 
    int? AttributeTwo{ get; set; } 
} 

私は私の問題はXmlSubEntryの属性が正しくシリアル化されることは決してありませんということです以下のXML

<?xml version="1.0" encoding="utf-8"?> 
<Root xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <XmlEntries> 
    <XmlEntry> 
     <XmlSubEntries> 
     <XmlSubEntry> 
      <AttributeOne>P</AttributeOne> 
      <AttributeTwo>8</AttributeTwo> 
     </XmlSubEntry> 
     <XmlSubEntry> 
      <AttributeOne>S</AttributeOne> 
      <AttributeTwo>26</AttributeTwo> 
     </XmlSubEntry> 
     </XmlSubEntries> 
    </XmlEntry> 
    </XmlEntries> 
</Root> 

を送信するためにシオマネキを使用してきました。 apiControllerエントリでMethodCallをデバッグすると、XmlSubEntryが2つのXmlSubEntryのリストである1つのXmlEntryを含むリストになりますが、属性(AttributeOneおよびAttributeTwo)は常にnullです。

私はクラスに注釈を付けることを試みました。すべての点で私はできることがありますが、修正をシリアル化する属性はまだ得られません。

私が間違っていることを理解するのに役立つXML-ninjasはありますか?

答えて

0

私はあなたに与えることができる最善のヒントは、逆にこれを行うことです - いくつかのデータを追加し、それをXMLにシリアライズし、どのように見えるかを見てください。それは通常あなたが間違っている場所を指します。

ただし、この場合、は非常にになります。あなたが持っている唯一の問題は、プライベートプロパティを連載できないので公開することです:

public class XmlSubEntry 
{ 
    public string AttributeOne { get; set; } 
    public int? AttributeTwo { get; set; } 
} 
+0

ありがとう。私は必要以上に複雑にしていました。その解決策は私の目の前に隠れていた。 :) –

関連する問題