Flex3问题使用json对象获取数组格式
{"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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的循环似乎有点不对劲。首先,您可能需要重新考虑“for ...in”循环与“foreach”循环的使用。这篇文章:for...in 与 for every 解释了这些差异说白了。
您可能还想阅读本文,了解有关对象内省的更多信息 (一种在运行时确定类属性的技术——您想要做什么 做...)。
无论如何,这里的问题是您要循环的内容。如果这里的目标是循环遍历“object”的属性值并将它们添加到数组或数组集合中,那么您就几乎完成了 -
使用“foreach”循环您可以这样做:
希望这有帮助:)
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:
Hope this helps :)