2017-08-04 32 views
-1

我試圖從SOAP Web服務中提取JSON數據。我正在使用Swift Alamofire圖書館。我收到一個錯誤,你能幫我解決這個問題嗎?使用Swift從SOAP中抽取JSON數據Alamofire

Alamofire.request("http://service.ceylaner.com.tr/suntech/HotelApps_WebServices.asmx").responseJSON { response in 
    print("Request: \(String(describing: response.request))") 
    print("Response: \(String(describing: response.response))") 
    print("Result: \(response.result)") 

    if let json = response.result.value { 
     print("JSON: \(json)") 
    } 

    if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) { 
     print("Data: \(utf8Text)") 
    } 
} 

代碼輸出如下。

該Web服務帶來的鏈接頁面,但我想獲取JSON數據。我正在尋找一種方法從SOAP Web服務獲取json數據。

Request: Optional(http://service.ceylaner.com.tr/suntech/HotelApps_WebServices.asmx) 
Response: Optional(<NSHTTPURLResponse: 0x618000025c00> { URL: http://service.ceylaner.com.tr/suntech/HotelApps_WebServices.asmx } { status code: 200, headers { 
    "Cache-Control" = "private, max-age=0"; 
    "Content-Length" = 6927; 
    "Content-Type" = "text/html; charset=utf-8"; 
    Date = "Fri, 04 Aug 2017 12:18:51 GMT"; 
    Server = "Microsoft-IIS/10.0"; 
    "X-AspNet-Version" = "4.0.30319"; 
    "X-Powered-By" = "ASP.NET"; 
} }) 
Result: FAILURE 
Data: 

<html> 

    <head><link rel="alternate" type="text/xml" href="/suntech/HotelApps_WebServices.asmx?disco" /> 

    <style type="text/css"> 

     BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } 
     #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } 
     A:link { color: #336699; font-weight: bold; text-decoration: underline; } 
     A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } 
     A:active { color: #336699; font-weight: bold; text-decoration: underline; } 
     A:hover { color: cc3300; font-weight: bold; text-decoration: underline; } 
     P { color: #000000; margin-top: 0px; margin-bottom: 12px; font-family: Verdana; } 
     pre { background-color: #e5e5cc; padding: 5px; font-family: Courier New; font-size: x-small; margin-top: -5px; border: 1px #f0f0e0 solid; } 
     td { color: #000000; font-family: Verdana; font-size: .7em; } 
     h2 { font-size: 1.5em; font-weight: bold; margin-top: 25px; margin-bottom: 10px; border-top: 1px solid #003366; margin-left: -15px; color: #003366; } 
     h3 { font-size: 1.1em; color: #000000; margin-left: -15px; margin-top: 10px; margin-bottom: 10px; } 
     ul { margin-top: 10px; margin-left: 20px; } 
     ol { margin-top: 10px; margin-left: 20px; } 
     li { margin-top: 10px; color: #000000; } 
     font.value { color: darkblue; font: bold; } 
     font.key { color: darkgreen; font: bold; } 
     font.error { color: darkred; font: bold; } 
     .heading1 { color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal; background-color: #003366; margin-top: 0px; margin-bottom: 0px; margin-left: -30px; padding-top: 10px; padding-bottom: 3px; padding-left: 15px; width: 105%; } 
     .button { background-color: #dcdcdc; font-family: Verdana; font-size: 1em; border-top: #cccccc 1px solid; border-bottom: #666666 1px solid; border-left: #cccccc 1px solid; border-right: #666666 1px solid; } 
     .frmheader { color: #000000; background: #dcdcdc; font-family: Verdana; font-size: .7em; font-weight: normal; border-bottom: 1px solid #dcdcdc; padding-top: 2px; padding-bottom: 2px; } 
     .frmtext { font-family: Verdana; font-size: .7em; margin-top: 8px; margin-bottom: 0px; margin-left: 32px; } 
     .frmInput { font-family: Verdana; font-size: 1em; } 
     .intro { margin-left: -15px; } 

    </style> 

    <title> 
    HotelApps_WebServices Web Hizmeti 
</title></head> 

    <body> 

    <div id="content"> 

     <p class="heading1">HotelApps_WebServices</p><br> 



     <span> 

      <p class="intro">Aşağıdaki işlemler desteklenmektedir. Tam bir tanımlama için lütfen <a href="HotelApps_WebServices.asmx?WSDL">Hizmet Tanımını</a> gözden geçirin. </p> 


       <ul> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=BI_WebLink">BI_WebLink</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetCameraList">GetCameraList</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetHotels">GetHotels</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetInfo">GetInfo</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetInfo_Photo">GetInfo_Photo</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetMainMenu">GetMainMenu</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=GetSubMenu">GetSubMenu</a> 


       </li> 
       <p> 

       <li> 
       <a href="HotelApps_WebServices.asmx?op=HelloWorld">HelloWorld</a> 


       </li> 
       <p> 

       </ul> 

     </span> 




    <span> 

    </span> 

     <span> 
      <hr> 
      <h3>Bu web hizmeti, varsayılan ad alanı olarak http://tempuri.org/ kullanıyor.</h3> 
      <h3>Öneri: Varsayılan ad alanını XML Web hizmeti genel kullanıma açılmadan önce değiştirin.</h3> 
      <p class="intro">Her XML Web hizmetinin, istemci uygulamalarının kendisini Web üzerindeki diğer hizmetlerden ayırt edebilmesi için benzersiz bir ad alanı olmalıdır. Geliştirilmekte olan XML Web hizmetleri için http://tempuri.org/ adresi kullanılabilir. Ancak yayımlanmış XML Web hizmetleri daha kalıcı bir ad alanı kullanmalıdır.</p> 
      <p class="intro">XML Web hizmetiniz sizin denetiminizde olan bir ad alanı tarafından tanımlanmalıdır. Örneğin şirketinizin Internet etki alanı adını ad alanının bir parçası olarak kullanabilirsiniz. Pek çok XML Web hizmeti ad alanı URL gibi görünse de, Web üzerindeki gerçek kaynakları işaret etmeleri gerekmez. (XML Web hizmeti ad alanları, URI'lerdir.)</p> 
      <p class="intro">ASP.NET kullanılarak oluşturulan XML Web hizmetlerinde, varsayılan ad alanını değiştirmek için WebService özniteliğinin Namespace özelliği kullanılabilir. WebService özniteliği, XML Web hizmeti yöntemlerini içeren sınıf için geçerli bir özniteliktir. Aşağıda ad alanını "http://microsoft.com/webservices/" olarak belirleyen bir kod örneği görülüyor:</p> 
      <p class="intro">C#</p> 
      <pre>[WebService(Namespace="http://microsoft.com/webservices/")] 
public class MyWebService { 
    // uygulama 
}</pre> 
      <p class="intro">Visual Basic</p> 
      <pre>&lt;WebService(Namespace:="http://microsoft.com/webservices/")&gt; Public Class MyWebService 
    ' uygulama 
End Class</pre> 

      <p class="intro">C++</p> 
      <pre>[WebService(Namespace="http://microsoft.com/webservices/")] 
public ref class MyWebService { 
    // uygulama 
};</pre> 
      <p class="intro">XML ad alanları hakkında daha fazla bilgi için <a href="http://www.w3.org/TR/REC-xml-names/">XML'de ad alanları</A> ile ilgili W3C önerilerine bakın.</p> 
      <p class="intro">WSDL konusunda daha fazla bilgi için, <a href="http://www.w3.org/TR/wsdl">WSDL Belirtimi'ne</a> bakın.</p> 
      <p class="intro">URI'ler hakkında daha fazla bilgi için, <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a> belgesine bakın.</p> 
     </span> 




    </body> 
</html> 

我在查爾斯計劃中檢查我的Web服務。 json數據來自xml標籤。 enter image description here

+0

也請張貼錯誤 – Simon

+0

我添加的代碼輸出。感謝您的關注。 –

+0

服務器的響應不是JSON,它是HTML,所以我不清楚爲什麼你會試圖將其解析爲JSON ... – Moritz

回答

0

我想這是因爲你忘了在info.plist中添加一行 enter image description here

+0

謝謝Dmytro,我檢查了我在info.plist添加的分裂關節 –

+0

。 –