Fórum Consumir DataSnap JSON feito em Delphi XE2 com FLEX #445261
12/06/2013
0
Alguem tem um exemplo funcional para consumir Consumir DataSnap JSON feito em Delphi XE2 com FLEX tentei dessa forma
e não obtenho o resultado, pelo browse os dados vem perfeito em JSON.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
height="300" width="600">
<mx:Script>
<![CDATA[
import com.adobe.serialization.json.JSON;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
private function Consultar():void{
var datasnapService:HTTPService = new HTTPService();
datasnapService.showBusyCursor = true;
datasnapService.url = "http://localhost:8088/datasnap/rest/TServerMethods/empresas";
datasnapService.addEventListener(ResultEvent.RESULT, ConsultarResultado);
datasnapService.send();
}
private function ConsultarResultado(re:ResultEvent):void{
var jo:Object = JSON.decode(re.result.toString());
var arr:Array = jo["result"][0];
var DataGriProvider:ArrayCollection = new ArrayCollection(arr);
DataGrid.dataProvider = DataGriProvider;
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%" >
<mx:HBox width="100%" height="10%" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10">
<mx:Button label="Consultar" width="117" click="Consultar()"/>
</mx:HBox>
<mx:HBox width="100%" height="90%" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10">
<mx:DataGrid id="DataGrid" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Código" dataField="EMPCOD" width="50"/>
<mx:DataGridColumn headerText="Nome" dataField="EMPNOM" width="300"/>
</mx:columns>
</mx:DataGrid>
</mx:HBox>
</mx:VBox>
</mx:Application>
e não obtenho o resultado, pelo browse os dados vem perfeito em JSON.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
height="300" width="600">
<mx:Script>
<![CDATA[
import com.adobe.serialization.json.JSON;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
private function Consultar():void{
var datasnapService:HTTPService = new HTTPService();
datasnapService.showBusyCursor = true;
datasnapService.url = "http://localhost:8088/datasnap/rest/TServerMethods/empresas";
datasnapService.addEventListener(ResultEvent.RESULT, ConsultarResultado);
datasnapService.send();
}
private function ConsultarResultado(re:ResultEvent):void{
var jo:Object = JSON.decode(re.result.toString());
var arr:Array = jo["result"][0];
var DataGriProvider:ArrayCollection = new ArrayCollection(arr);
DataGrid.dataProvider = DataGriProvider;
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%" >
<mx:HBox width="100%" height="10%" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10">
<mx:Button label="Consultar" width="117" click="Consultar()"/>
</mx:HBox>
<mx:HBox width="100%" height="90%" paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10">
<mx:DataGrid id="DataGrid" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Código" dataField="EMPCOD" width="50"/>
<mx:DataGridColumn headerText="Nome" dataField="EMPNOM" width="300"/>
</mx:columns>
</mx:DataGrid>
</mx:HBox>
</mx:VBox>
</mx:Application>
Aparecido Silva
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)