2013-01-15 99 views
1

使用代碼自爆我試圖解析以下肥皂響應。類型強制失敗:無法將XMLList @ 106e9af1轉換爲mx.collections.IList

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 
       xmlns:components="components.*" 
       xmlns:hellos="services.hellos.*" 
       height="957" creationComplete="initApp()" > 
    <fx:Style source="Styles.css"/> 
    <fx:Script> 

     <![CDATA[ 

      import mx.controls.Alert; 

      private namespace invesbot = "http://Services.com"; 
      use namespace invesbot; 

      private namespace a = "http://schemas.xmlsoap.org/soap/envelope/"; 
      private namespace b = "http://www.w3.org/2001/XMLSchema"; 
      private namespace c = "http://www.w3.org/2001/XMLSchema-instance"; 
      use namespace a; 
      use namespace b; 
      use namespace c; 

      [Bindable] 
      var _result:* 



      private function initApp():void 
      { 
       myService.mycustomers(); 
      } 

     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <mx:WebService id="myService" wsdl="http://localhost:8081/WebServiceTest/services/Hellos?wsdl" 
         showBusyCursor="true" 
         fault="Alert.show(event.fault.faultString), 'Error'"> 
      <mx:operation name="mycustomers" resultFormat="e4x"> 
       <mx:request> 
       </mx:request> 
      </mx:operation> 
     </mx:WebService> 

    </fx:Declarations> 
<mx:HBox> 
     <mx:Text 
      text="{myService.mycustomers.lastResult.mycustomersReturn.name}" 
      /> 
    </mx:HBox> 
</s:Application> 

SOAP響應是如下

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
    <mycustomersResponse xmlns="http://Services.com"> 
     <mycustomersReturn> 
     <age>28</age> 
     <name>John</name> 
     </mycustomersReturn> 
     <mycustomersReturn> 
     <age>29</age> 
     <name>Alex</name> 
     </mycustomersReturn> 
     <mycustomersReturn> 
     <age>30</age> 
     <name>Jack</name> 
     </mycustomersReturn> 
    </mycustomersResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

使用上述代碼的輸出將是

<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">John</name> 
<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Alex</name> 
<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Jack</name> 

但是當我使用以下代碼來把結果在下拉框中它給出以下錯誤

<s:FormItem label="Employee:"> 
     <s:DropDownList id="dropDownList3" 
         labelField="name" 
         dataProvider ="{myService.mycustomers.lastResult.mycustomersReturn}"/> 
    </s:FormItem> 

TypeError:錯誤#1034:類型強制失敗:無法將XMLList @ 106e9af1轉換爲mx.collections.IList。

+0

http://stackoverflow.com/questions/10777471/adobe-flex-cannot-convert-xmllist-to-mx-collections-ilist的重複 – Avik

回答

1

您必須將數據包裝在XMLListCollection中 與數組相同的事情,您必須將它們包裝到ArrayCollections中。 使用新版本的flex sdk 4.9,您還可以創建VectorLists和VectorCollections。

例如:

​​
+0

一些樣品實際上是這裏很有用 – ShaunOReilly

相關問題