2
我在網上看到很多示例,但是我無法理解應用程序,或者示例與我的轉換太不相同。我有一個XML將XML字符串反序列化爲對象VB.NET
<Interfaces>
<Interface>
<InterfaceCode>987</InterfaceCode>
<AccessID>asdf</AccessID>
<Password>654321</Password>
</Interface>
<Interface>
<InterfaceCode>789</InterfaceCode>
<AccessID> </AccessID>
<Password> </Password>
</Interface>
</Interfaces>
而下面的類
<Serializable(), XmlRoot("Interfaces"), XmlType("Interfaces")>
Public Class InterfacesModel
Property Interfaces As New List(Of InterfaceModel)
End Class
<Serializable(), XmlType("Interface")>
Public Class InterfaceModel
Property InterfaceCode As String
Property AccessID As String
Property Password As String
End Class
下面的代碼生成一個InterfacesModel
一個空Interfaces
列表:
Dim str As String = xmlString
Dim interfaces As InterfacesModel
Dim serializer As New XmlSerializer(GetType(InterfacesModel))
Using reader As TextReader = New StringReader(str)
interfaces = serializer.Deserialize(reader)
End Using
我希望它來填充接口作爲列出(InterfaceModel的),以便我可以在Interfaces上爲每個接口執行一個操作,併爲每個接口執行一些操作。