i want to convert the result in spark datagrid cotrol to json data
i'm using actionscript 3 and Flex
this is my datagrid :
<s:DataGrid id="_gridcentre" left="5" right="5" top="5" bottom="5"
borderVisible="true" dataProvider="{GetCentreResult.lastResult}"
fontSize="11">
<s:columns>
<s:ArrayList>
<s:GridColumn visible="false" dataField="Codecentre"headerText="Code"/>
<s:GridColumn dataField="Nomcentre" headerText="Nom Centre"/>
<s:GridColumn dataField="Typecentre" headerText="Type Centre"/>
<s:GridColumn dataField="Milieurecepteur" headerText="Milieu Récepteur"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
i did this code, but it not working :
var result:Object = _gridcentre.dataProvider as Object;
var myJson:String = JSON.stringify(result);
i can read my objects, when i iterate my object < result > like this :
for each (var item:Centre in result)
{
Alert.show(item.Codecentre.toString());
}
thanks for help
The dataprovider is usually an instance of a array alike class. Most likely spark's ArrayList or ArrayCollection class instance, which means that You can try toArray() method, which will return the raw objects contaned into, or if this fail - try to find the type of the data provider and invoke it's appropriate method to convert contained objects into array or some other structure which you can iterate trough.