Alamofire XML解析错误-1017

时间:2015-10-28 20:35:13

标签: xml swift parsing alamofire

使用Alamofire 3.1.0和Swift 2

我正在尝试解析XML,但是我收到以下错误

  

错误域= NSURLErrorDomain代码= -1017“无法解析响应”UserInfo = {NSUnderlyingError = 0x7f83f9449d50 {错误域= kCFErrorDomainCFNetwork代码= -1017“(null)”UserInfo = {_ kCFStreamErrorCodeKey = -1,_kCFStreamErrorDomainKey = 4}}, NSErrorFailingURLStringKey =“与NSErrorFailingURLKey相同”,NSErrorFailingURLKey = http://webservices.ns.nl/ns-api-storingen,_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -1,NSLocalizedDescription =无法解析响应}

我的GET功能

private func GET(parameters: [String : String]) {
    Alamofire.request(.GET, URL, parameters: parameters, encoding: .PropertyList(.XMLFormat_v1_0, 0))
        .authenticate(user: user, password: password)
        .responsePropertyList { response in
            if let error = response.result.error {
                print(error)
            } else if let array = response.result.value as? [[String:String]] {
                if array.isEmpty {
                    print("No data")
                } else {
                    // do stuff
                }
            }
    }
}

This is the server response

有人能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:0)

我使用以下代码(使用SWXMLHash)

private func GET(parameters: [String : String]) {
    Alamofire.request(.GET, URL, parameters: parameters)
        .authenticate(user: user, password: password)
        .responseString { response in
            let xml = SWXMLHash.parse(response.result.value!)
            print(xml["Storingen"]["Ongepland"]["Storing"]["Traject"].element!.text!)
                }
}