在iOS Swift 3中,可以通过以下步骤从SOAP Web服务方法中获取JSON数组字符串:
import Alamofire
func getJSONFromSOAPService() {
let soapMessage = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:example=\"http://www.example.com/\"><SOAP-ENV:Body><example:GetData></example:GetData></SOAP-ENV:Body></SOAP-ENV:Envelope>"
let headers: HTTPHeaders = [
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://www.example.com/GetData"
]
Alamofire.request("http://example.com/soap-service", method: .post, parameters: [:], encoding: soapMessage, headers: headers).responseString { response in
switch response.result {
case .success(let value):
// 处理SOAP响应,提取JSON数组字符串
if let jsonStartIndex = value.range(of: "{"),
let jsonEndIndex = value.range(of: "}", options: .backwards) {
let jsonString = value[jsonStartIndex.lowerBound...jsonEndIndex.upperBound]
print(jsonString)
}
case .failure(let error):
print(error)
}
}
}
soapMessage
替换为你的SOAP请求消息。同时,你还需要设置正确的URL和SOAPAction。这是一个简单的示例,它演示了如何使用Alamofire库从SOAP Web服务方法中获取JSON数组字符串。你可以根据实际需求进行修改和扩展。
领取专属 10元无门槛券
手把手带您无忧上云