I getting the result as an array of strings like this
我将结果作为这样的字符串数组得到
["India","America","Australia","China","Russia"]
And I'm using Alamofire to get the response using code. There's no error, but I got the result as null. Please help in parsing this.
我正在使用Alamofire使用代码获取响应。没有错误,但我得到的结果为null。请帮助解析这个。
sessionManager?.request(strURL, method: method, parameters: params, encoding: encoding , headers: headers).responseJSON { (response) in
switch response.result {
case .success:
let resJson = JSON(response.result.value!)
success(resJson)
break
case .failure(let error):
failure(error as NSError)
break
}
}
2 个解决方案
#1
2
Try this:
尝试这个:
if let responseData = response.result.value{
let responsevalue = responseData as? [String]
}
#2
0
For anyone looking for another derived answer, just put this chunk of code after Alamofire.request(...)
:
对于任何寻找另一个派生答案的人,只需将这段代码放在Alamofire.request(...)之后:
.responseJSON(completionHandler: { (response) in
switch response.result{
case .success(let value):
// Here is your array of String
let arrayOfStrings = value as? [String]
case .failure(let error):
// Some code when error happens...
print(error.localizedDescription)
}
})
#1
2
Try this:
尝试这个:
if let responseData = response.result.value{
let responsevalue = responseData as? [String]
}
#2
0
For anyone looking for another derived answer, just put this chunk of code after Alamofire.request(...)
:
对于任何寻找另一个派生答案的人,只需将这段代码放在Alamofire.request(...)之后:
.responseJSON(completionHandler: { (response) in
switch response.result{
case .success(let value):
// Here is your array of String
let arrayOfStrings = value as? [String]
case .failure(let error):
// Some code when error happens...
print(error.localizedDescription)
}
})