gpt4 book ai didi

ios - 通过 Alamofire 调用 API 但遇到一些问题

转载 作者:行者123 更新时间:2023-11-30 11:19:06 25 4
gpt4 key购买 nike

我通过 Alamofire 调用 api,并且完美地传递了请求参数。我已经检查过了,但仍然没有得到回复。我收到成功消息,但没有收到响应数据。下面是我的代码,

let API = "http://siestalaminates.com/admin/index.php/Webservice/getcategorybybrandid"
let subcate = ["brand_id": brandid] as [String:Any]
Alamofire.request(API, method: .post, parameters: subcate ).responseJSON
{
response in
//printing response
print(response)
let result = response.result
// let obj=result
if let dict = result.value as? Dictionary<String,AnyObject>{
if let subdata = dict["data"]{
self.subcatelist = subdata as! [AnyObject]
self.subcategory_collection.reloadData()

}
}
self.activityIndicator.stopAnimating()
}

动态传递品牌 ID::

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
///print("==>",cateid[indexPath.row] as NSString)

let vc = self.storyboard?.instantiateViewController(withIdentifier: "ProductsubcategoryViewController") as! ProductsubcategoryViewController

vc.brandid = (self.brandid[indexPath.row] as NSString) as String?


self.present(vc, animated: false, completion: nil)
}

如果我静态传递brand_id,那么我会得到响应,但是当我动态传递它时,它会完美传递,但不会得到响应。

最佳答案

替换以下行:

   let subcate = ["brand_id": brandid] as [String:Any]

与:

   let subcate = ["brand_id": brandid!] as [String:Any]

您遇到的唯一问题似乎是可选值和必需值。我认为您不擅长可选和必需的链接。

关于ios - 通过 Alamofire 调用 API 但遇到一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51477890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com