Flex3问题使用json对象获取数组格式

发布于 2024-12-02 00:09:23 字数 599 浏览 1 评论 0原文

{"object":[{"cyclename":"PE cycle","avgRunTime":"05:30","actualStartTime":"08/27/2011 02:40:08","actualEndTime":"08/27/2011 05:26:38","startTime":"02:40","status":"G"}]}

这是我的文件,我想将其解析为数组并显示状态,但我正在获取诸如 [object object][object Object]、[object Object]、[object Object] 等数据。 ..

我如何将它解析为数据提供者,我编写的代码是

private function cycle_resultHandler(event:ResultEvent):void
{

   var myData:Object = JSON.decode(event.result as String);

   for(var i:String in myData['object'])
   {

     dProvider.addItem(myData['object'][i]);

   }

}
{"object":[{"cyclename":"PE cycle","avgRunTime":"05:30","actualStartTime":"08/27/2011 02:40:08","actualEndTime":"08/27/2011 05:26:38","startTime":"02:40","status":"G"}]}

this is my file and i want to parse it to array and get the status displayed but i am getting data like [object object][object Object],[object Object],[object Object] etc...

how do i parse it to a dataprovider and code i have written is

private function cycle_resultHandler(event:ResultEvent):void
{

   var myData:Object = JSON.decode(event.result as String);

   for(var i:String in myData['object'])
   {

     dProvider.addItem(myData['object'][i]);

   }

}

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

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

发布评论

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

评论(1

清醇 2024-12-09 00:09:23

你的循环似乎有点不对劲。首先,您可能需要重新考虑“for ...in”循环与“foreach”循环的使用。这篇文章:for...in 与 for every 解释了这些差异说白了。

您可能还想阅读本文,了解有关对象内省的更多信息 (一种在运行时确定类属性的技术——您想要做什么 做...)。

无论如何,这里的问题是您要循环的内容。如果这里的目标是循环遍历“object”的属性并将它们添加到数组或数组集合中,那么您就几乎完成了 -

使用“foreach”循环您可以这样做:

private function cycle_resultHandler(event:ResultEvent):void {
    var myData:Object = JSON.decode(event.result as String);
    //Here we are iterating over the values in the "object" object as opposed to it's keys.
    for each(var str:String in myData['object']) {
        dProvider.addItem(str);
    }
}

希望这有帮助:)

Your looping seems to be a bit off. First off you may want to reconsider your usage of a "for ...in" loop vs. a "for each" loop. This article: for...in vs. for each explains the differences quite plainly.

You may also want to give this article a read for more information on object introspection (a technique for determining the properties of a class at runtime -- what you are trying to do...).

In any case, the issue here is what you are looping over. If the goal here is to loop over the property values of "object" and add them to an array or arraycollection, you're almost there--

utilizing a "for each" loop you might do this instead:

private function cycle_resultHandler(event:ResultEvent):void {
    var myData:Object = JSON.decode(event.result as String);
    //Here we are iterating over the values in the "object" object as opposed to it's keys.
    for each(var str:String in myData['object']) {
        dProvider.addItem(str);
    }
}

Hope this helps :)

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