Alamofire can't access keys of json response

前端 未结 3 1995
孤街浪徒
孤街浪徒 2021-01-26 05:20

I\'m new to using Alamofire and have encountered an issue. I\'m able to run the following code to print out all the data from an API endpoint.

Alamofire.request(         


        
3条回答
  •  礼貌的吻别
    2021-01-26 06:02

    You should add ! at the end of code before ) to force unwrap the value

       Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in
          if let JSON = response.result.value {
          let json = JSON as! [String: Any]
          print(json["firstkey"]!)
       }
    }
    

提交回复
热议问题