简体   繁体   中英

Swift Alamofire Request Error - Extra Argument in call

I am getting an error when I am trying to request using Alamofire. The error says that there is an 'extra argument in call'.

class SwiftStockKit {

class func fetchStocksFromSearchTerm(term: String, completion:@escaping (_ stockInfoArray: [StockSearchResult]) -> ()) {
    DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async {

        let searchURL = "http://autoc.finance.yahoo.com/autoc"

        Alamofire.request(.GET, searchURL, parameters: ["query": term, "region": 2, "lang": "en"]).responseJSON { response in

            if let resultJSON = response.result.value as? [String : AnyObject]  {

                if let jsonArray = (resultJSON["ResultSet"] as! [String : AnyObject])["Result"] as? [[String : String]] {

                    var stockInfoArray = [StockSearchResult]()
                    for dictionary in jsonArray {
                        stockInfoArray.append(StockSearchResult(symbol: dictionary["symbol"], name: dictionary["name"], exchange: dictionary["exchDisp"], assetType: dictionary["typeDisp"]))
                    }

                    dispatch_async(dispatch_get_main_queue()) {
                        completion(stockInfoArray: stockInfoArray)
                    }
                }
            }
        }
    }
}

The line that is giving me an error is:

Alamofire.request(.GET, searchURL, parameters: ["query": term, "region": 2, "lang": "en"]).responseJSON { response in

if anyone could fix this I would be really grateful, thanks

尝试将您的请求更改为以下内容:

Alamofire.request(searchURL, method: .get, parameters: ["query": term, "region": 2, "lang": "en"], encoding: JSONEncoding.default, headers: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM