草庐IT

Alamofire-SwiftyJSON

全部标签

ios - 从 PromiseKit/Alamofire 返回一个 Promise

我正在尝试做这件看似微不足道的事情:staticfunclist()->Promise{letendpoint="\(self.baseUrl)/v1/activities"returnPromise{fulfill,rejectinself.fetchHeaders{(headers)inreturnAlamofire.request(endpoint,method:.get,parameters:nil,encoding:JSONEncoding.default,headers:headers).validate().responseJSON().then(){responsein

swift - 在 Swift 中使用 Alamofire 防止重定向响应

我正在寻找示例代码如何在请求WebAPI时防止重定向响应(状态代码3xx)。我在Alamofire1.2中使用Swift。我试过:delegate.taskWillPerformHTTPRedirection={(session:NSURLSession!,task:NSURLSessionTask!,response:NSHTTPURLResponse!,request:NSURLRequest!)inreturnnil}但不工作我也试过:https://github.com/Alamofire/Alamofire/pull/350/files并将我自己的代码更改为:varacc=s

ios - 如何同步多个 Alamofire 请求

我有多个请求:vardata1:MyData?vardata2:MyData?vardata3:MyData?funcmakeRequest(url:String,completion:(result:ResponseResult,data:MyData?)->Void){Alamofire.request(.GET,url).responseJSON{responseinswitchresponse.result{case.Success(letJSON):completion(result:.Success,MyData(JSON))case.Failure(leterror):c

ios - 使用 Alamofire 获取 JSON 并解码 - Swift 4

我有一个API,我也想获取请求。但是我尝试使用JSONDecoder来转换数据类型,但我失败了。我不知道如何像下面的数据一样解码这个Json。我想使用json["response"]内容设置我的用户结构。对我有什么建议吗?谢谢。ErrorDomain=NSCocoaErrorDomainCode=4865"Novalueassociatedwithkeyid("id")."UserInfo={NSCodingPath=(),NSDebugDescription=Novalueassociatedwithkeyid("id").}这是JSON数据:{"status":"success",

ios - Alamofire 无法使用 cocoapods 构建

我正在使用:OSX10.11.3Xcode7.21cocoapods0.39.0这是我的播客文件source'https://github.com/CocoaPods/Specs.git'platform:ios,'9.0'use_frameworks!pod'Alamofire','~>3.0'当我尝试构建我的项目时,Alamofire出现23个错误。随机示例:在case之后应为':'我已经尝试重新启动xcode、清理、构建、构建alamofire,rm-rf~/Library/Developer/Xcode/DerivedData,但所有结果都相同。这是我第一次使用cocoapod

ios - 如何使用 SwiftyJSON 在 Swift 中将字符串转换为 JSON 数组?

我有一个字符串格式的json数组,但是由于某些原因我无法使用SwiftyJSON将它转换为JSON数组。它可能与json结构有关。我该怎么做?这是字符串[{"Disabled":false,"Group":null,"Selected":false,"Text":"1","Value":"1"},{"Disabled":false,"Group":null,"Selected":false,"Text":"2","Value":"2"},{"Disabled":false,"Group":null,"Selected":false,"Text":"3","Value":"3"},{"D

ios - 使用 SwiftyJSON 对 Alamofire GET 参数进行 URL 编码

我试图让Alamofire在GET请求中发送以下参数,但它发送的是乱码:filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]}//www.example.com/example?filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]}//ObviouslyURLencoded这是我的代码:letjsonObject=["$and":[["name":["$bw":string],"country":"gb"]]]letjson=JSON(jsonObject)print

ios - 如何在 swift 5 alamofire 5.0.3 中使用 Alamofires ServerTrustPolicy.disableEvaluation

在alamofire4中,我使用这段代码来禁用服务器评估:privatevarManager:Alamofire.Session={//CreatetheservertrustpoliciesletserverTrustPolicies:[String:ServerTrustPolicy]=["serverurl.com":.disableEvaluation]//Createcustommanagerletconfiguration=URLSessionConfiguration.defaultconfiguration.httpAdditionalHeaders=Alamofire

swift - 在 Alamofire 中更改超时时间

如何更改超时间隔时间以在Alamofire中获得长时间运行的API响应。我试过以下代码:letconfiguration=NSURLSessionConfiguration.defaultSessionConfiguration()configuration.timeoutIntervalForRequest=300.0//secondsletalamofireManager=Alamofire.Manager(configuration:configuration)alamofireManager.request(method,urlString,parameters:paramet

json - 使用 SwiftyJSON 处理 nil 值

我正在使用JSONapi获取数据并且一切正常,但我真的不喜欢我处理结果的方式,如果它是nil。这是今天的样子:我得到我的JSON,然后我迭代它并执行以下操作letobj=Obj()obj.name=json["name"].string??""obj.age=json["age"].string??""obj.length=json["length"].string??""所以我检查例如json["name"].string是否有一个值,否则我给它分配一个空的""。这是使用SwiftyJSON的方法还是有更简洁的方法?问题是有时json["name"].string有一个值但不是jso