在 Actionscript 中将 XML 字符串转换为对象
我对 AS 还很陌生,我假设有一种方法可以做到这一点,但我只是没有弄清楚。基本上,我尝试使用返回 xml 并返回对象的服务,而不管 xml 的结构如何。在.Net中,我使用XmlSerializer.Deserialize类...AS中有等效的吗?
我能够找到 SimpleXMLDecoder 但我似乎无法让它工作 - 它看起来也可能只适用于节点?不管怎样,那里的例子很少而且很难理解,我只是想知道如何像这样获取 xml:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Company>
<Id>2</Id>
<Name>Stan</Name>
<Size>10</Size>
</Company>;
并简单地将它变成一个 Object - 这是否可以在不编写我自己的解析器的情况下实现?谢谢。
I am pretty new to AS, and I am assuming there is a way to do this and I am just not figuring it out. Basically, I am trying to use a service that returns xml and return an Object regardless of the structure of the xml. In .Net I use the XmlSerializer.Deserialize class... is there equivalent in AS?
I was able to find SimpleXMLDecoder but I can't seem to get it to work - it also looks like it might only work with nodes? Either way, the examples out there are sparse and hard to follow, I just want to know how to take xml like this:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Company>
<Id>2</Id>
<Name>Stan</Name>
<Size>10</Size>
</Company>;
And simply turn it into an Object - is this possible without writing my own parser? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ActionScript 有自己的
XML
解析器,因此您无需编写自己的解析器。来自字符串的 XML
如果您有一个
String
需要转换,您只需将其转换为XML
内嵌几行代码,如下所示:来自外部文件的 XML
否则,您可以只需以这种方式在运行时加载它:
使用链接编辑
一些不错的链接来开始工作:
基本
http://blog.theflashblog.com/?p=242
一些不错的 E4X提示和操作方法
http://www.senoptic.com/flash/tutorials/as3withflashcs3/?page =4
希望这有帮助。再见!
ActionScript has its own
XML
parser then you don't need to write yours.XML from a String
If you have a
String
to convert, you can just convert it asXML
inline with few lines of code like this:XML from an external file
Otherwise you can just load it in runtime in this way:
Edited with links
Some nice links to start working:
The Basic
http://blog.theflashblog.com/?p=242
Some nice E4X tips and how-to
http://www.senocular.com/flash/tutorials/as3withflashcs3/?page=4
Hope this helps. Ciao!
您可以使用
HTTPService< /code>
这里有一个很好的例子...
基本上,当您检索结果时,它会将结果从 XML 序列化为对象。
You can use the
HTTPService
There's a good example here...
Basically it will serialize the result into an object from XML when you retrieve it.