简体   繁体   中英

Cannot call value of non function type Data? SwiftyJSON

Tried almost every solution found here. But couldn't solve this issue.I am using Alamofire and swiftyJSON.

屏幕截图

Code below:

upload.responseJSON(completionHandler: { response in
                print("Request: \(String(describing: response.request))")   // original url request
                print("Response: \(String(describing: response.response))") // http url response
                print("Result: \(response.result)")                         // response serialization result
                print("Result Value: \(response.result.value.debugDescription)")
                spinner.stopAnimating()
                print(response.error.debugDescription)
                //print("\(response.result.error)")
                if response.result.isSuccess {
                    if let result = response.result.value {
                        print("JSON: \(result)") // serialized json response
                        let json = JSON(result)
                    }
                }
            })

Try to use this code:

        switch response.result {
        case .success(let value):
            let json = JSON(value)
            print(json)
        case .failure(let error): print(error)
        }

Check if this works

let json = JSON(result1)

Also there is a possibility that the result value is string. For that try this -

if let dataFromString = result1.data(using: .utf8, allowLossyConversion: false) {
    let json = JSON(data: dataFromString)
}

Let me know if any of this works for you else I will try to find out something else.

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