ios – AFNetworking和Swift

ios – AFNetworking和Swift,第1张

概述我正在尝试使用 swift获取 JSON响应. 我嗅到请求和响应 – >一切还好 但是返回值总是为零. let httpClient = AppDelegate.appDelegate().httpRequestOperationManager as AFHTTPRequestOperationManager; let path = "/daten/wfs"; let query 我正在尝试使用 swift获取 JSON响应.
我嗅到请求和响应 – >一切还好
但是返回值总是为零.
let httpClIEnt = AppDelegate.appDelegate().httpRequestoperationManager as AFhttpRequestoperationManager;    let path = "/daten/wfs";    let query = "?service=WFS&request=GetFeature&version=1.1.0&typename=ogDWIEn:AMPELOGD&srsname=epsg:4326&outputFormat=Json".stringByAddingPercentEscapesUsingEnCoding(NSUTF8StringEnCoding);    func successBlock(operation: AFhttpRequestoperation!,responSEObject: AnyObject!) {        println("JsON: " + "\(responSEObject)")    }    func errorBlock(operation: AFhttpRequestoperation!,error:NSError!) {        println("Error: " + error.localizedDescription)    }    let urlString = "\(path)" + "/" + "\(query)"    println("urlString: " + httpClIEnt.baseURL.absoluteString + urlString)

我也试过这样:

httpClIEnt.GET(urlString,parameters: nil,success: { (operation: AFhttpRequestoperation!,responSEObject: AnyObject!) -> VoID in            println("Success")            println("JsON: " + "\(responSEObject)")        },failure:{ (operation: AFhttpRequestoperation!,error:NSError!) -> VoID in            println("Failure")        })

…但是responSEObject总是似乎为零

[编辑]
也许原因是我的AppDelegate中可能出错的初始化:

var httpRequestoperationManager: AFhttpRequestoperationManager? // JAVA SERVER ClIEntclass func appDelegate() -> AppDelegate {    return UIApplication.sharedApplication().delegate as AppDelegate}func configureWebservice() {    let requestSerializer = AFJsONRequestSerializer()    requestSerializer.setValue("1234567890",forhttpheaderFIEld: "clIEntID")    requestSerializer.setValue("Test",forhttpheaderFIEld: "appname")    requestSerializer.setValue("1.0.0",forhttpheaderFIEld: "appVersion")    let responseSerializer = AFJsONResponseSerializer()    AFNetworkActivityIndicatorManager.sharedManager().enabled = true    // ##### http #####    let baseURL = NSURL(string: "http://data.wIEn.gv.at");    httpRequestoperationManager = AFhttpRequestoperationManager(baseURL: baseURL))    httpRequestoperationManager!.requestSerializer = requestSerializer    httpRequestoperationManager!.responseSerializer = responseSerializer}

任何建议我做错了什么?

亲爱的,史蒂夫

解决方法 Swift与Objective-C代码完全兼容,所以您的问题与Swift本身无关.在AFNetworking中,responSEObject有时可以为零.其中包括:

> A 204未返回任何内容状态代码,
>如果输出流设置为写入文件,
>如果验证期间的错误不是NSURLErrorCannotDecodeContentData(例如不可接受的内容类型)

查看#740和#1280了解更多信息.

总结

以上是内存溢出为你收集整理的ios – AFNetworking和Swift全部内容,希望文章能够帮你解决ios – AFNetworking和Swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1110600.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存