AS3 XML 到多维数组
我到处都看过,虽然有很多解释,但我似乎无法理解它。
这是我的 xml 结构:
<question>
<q1> Who coined the term “Clinical Psychology”? </q1>
<answer> Lightner Witmer </answer>
<option1> Stanley Hall </option1>
<option2> Lightner Witmer </option2>
<option3> Henry P. David </option3>
</question>
我可以循环遍历并挑选出问题和答案,然后将它们放入单独的数组中。我遇到的问题是循环并将选项拉入多维数组中,如下所示:
var one:Array = new Array( 3 );
one[0] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
one[1] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
one[2] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
任何帮助将不胜感激。
I've looked everywhere, and although there are many explanations, I can't seem to wrap my head around it.
Here is my xml structure:
<question>
<q1> Who coined the term “Clinical Psychology”? </q1>
<answer> Lightner Witmer </answer>
<option1> Stanley Hall </option1>
<option2> Lightner Witmer </option2>
<option3> Henry P. David </option3>
</question>
I can loop through fine and pick out the questions and answers, then throw them into separate arrays. The problem I'm having is looping and pulling the options into a multidimensional array like such:
var one:Array = new Array( 3 );
one[0] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
one[1] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
one[2] = ["Stanley Hall", "Lightner Witmer", "Henry P. David"];
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在可以检索问题的答案:
希望有帮助
answers for questions can now be retrieved:
Hope that helps
我不确定您是否以您想要的形式设置数组,但是,请关闭您发布的代码。
你尝试过吗?
对于这样的东西,我更喜欢有一个以对象作为元素的问题数组。每个对象都会保存有关该问题的所有信息。这将允许为每个问题分配一个自定义类别。或者可以使用基本的动态对象
I am not sure you are setting up the array in the form you want but, going off the code you posted.
Have you tried?
With something like this I would prefer to have a questions array with objects as the elements. Each object would hold all the info about that question. This would allow for a custom class to be assigned for each question. Or a basic dynamic object could be used