将 XML 数据解析为多维数组时出错

发布于 2024-08-26 00:11:02 字数 1340 浏览 2 评论 0原文

我仍在从 as2 过渡到 as3,我在将 XML 数据解析为多维数组时遇到问题,下面是 onComplete 处理程序,它成功跟踪“event.target.data”,但输出“A term is undefined and has no”跟踪 _vein_data[0][0].xPos 时的属性。我猜想有一种比这次尝试更简单的方法来实现它,

private function on_xml_completed(event:Event):void {
   var XMLPoints:XML = new XML(event.target.data);

   for ( var i:int = 0; i < XMLPoints.shape.length(); i++ )
    {
     var shapeArray:Array = new Array();
 _vein_data.push(shapeArray);

    for ( var j:int = 0; j < 4; i++ )
    {
  _vein_data[i].push({'xPos':XMLPoints.shape[i].point[j].@xPos,
          'yPos':XMLPoints.shape[i].point[j].@yPos});
 }
}


 trace(_vein_data[0][0].xPos)
   loadAsset();
  }

这是我的 XML 的一部分;

<items>
 <shape>
  <point xPos="60" yPos="23" />
  <point xPos="65" yPos="23" />
  <point xPos="93" yPos="85" />
  <point xPos="88" yPos="87" />
 </shape>
 <shape>
  <point xPos="88" yPos="87" />
  <point xPos="92" yPos="83" />
  <point xPos="145" yPos="174" />
  <point xPos="138" yPos="175" />
 </shape>
 <shape>
  <point xPos="138" yPos="175" />
  <point xPos="143" yPos="171" />
  <point xPos="147" yPos="211" />
  <point xPos="141" yPos="212" />
 </shape>
</items>  

预先感谢您对此的任何指导 凸轮

i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data to Multi dimensional array, below is the onComplete handler which is succesfully tracing 'event.target.data' but outputs 'A term is undefined and has no properties' when tracing _vein_data[0][0].xPos . I'm guessing there is a easier way to approach it than this attempt

private function on_xml_completed(event:Event):void {
   var XMLPoints:XML = new XML(event.target.data);

   for ( var i:int = 0; i < XMLPoints.shape.length(); i++ )
    {
     var shapeArray:Array = new Array();
 _vein_data.push(shapeArray);

    for ( var j:int = 0; j < 4; i++ )
    {
  _vein_data[i].push({'xPos':XMLPoints.shape[i].point[j].@xPos,
          'yPos':XMLPoints.shape[i].point[j].@yPos});
 }
}


 trace(_vein_data[0][0].xPos)
   loadAsset();
  }

here's a portion of my XML;

<items>
 <shape>
  <point xPos="60" yPos="23" />
  <point xPos="65" yPos="23" />
  <point xPos="93" yPos="85" />
  <point xPos="88" yPos="87" />
 </shape>
 <shape>
  <point xPos="88" yPos="87" />
  <point xPos="92" yPos="83" />
  <point xPos="145" yPos="174" />
  <point xPos="138" yPos="175" />
 </shape>
 <shape>
  <point xPos="138" yPos="175" />
  <point xPos="143" yPos="171" />
  <point xPos="147" yPos="211" />
  <point xPos="141" yPos="212" />
 </shape>
</items>  

thank you in advance for any guidance on this
Cam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若言繁花未落 2024-09-02 00:11:02

好的解决了,
问题是嵌套 for 循环中递增的 i,而不是 j++;

我的错。

ok resolved,
the problem was the incremented i on the nested for loop, instead of j++;

my bad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文