Alamofire can't access keys of json response

前端 未结 3 2049
孤街浪徒
孤街浪徒 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 05:51

    You are trying to get the value with getting the object, try this:

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

    Hope it will work!

提交回复
热议问题