Flex3 issue to get the array format using json object
{"object":[{"cyclename":"PE cycle","avgRunTime":"05:30","actualStartTime"开发者_Python百科:"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]);
}
}
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 :)
精彩评论