格式不正确SwiftyJSON

时间:2019-07-13 02:14:05

标签: swift swifty-json

在使用SwiftyJSON的同一个应用程序中,一种储蓄没有节省,另一种储蓄是两个代码是相同的。

错误是:由于数据格式不正确,因此无法读取。

func updateUser() {
        guard var dependent = mutableDependet else {
            return
        }

        if !Reachability.isConnectedToNetwork() {
            self.alert(title: "Erro", message: "Conecte-se para editar seu perfil!")
            return
        }

        dependent.country = self.countryTextfield.textfield.text ?? ""
        dependent.street = self.streetTextfield.textfield.text ?? ""
        dependent.number = self.numberTextfield.textfield.text ?? ""
        dependent.state = self.stateTexfield.textfield.text ?? ""
        dependent.country = self.countryTextfield.textfield.text ?? ""
        dependent.city = self.cityTextfield.textfield.text ?? ""
        dependent.zipCode = self.cepTextfield.textfield.text ?? ""
        dependent.neighborhood = (complementTextfield.textfield.text?.isEmpty ?? true) ? "n/a" : (complementTextfield.textfield.text ?? "")

        SVProgressHUD.show()
        view.isUserInteractionEnabled = false

        app.networkManager.updateDependent(dependent: dependent, pass: app.user.pass ?? "") {
            result in
            SVProgressHUD.dismiss()
            self.view.isUserInteractionEnabled = true
            do {
                try result.unwrap()
                self.delegate?.didUpdateDependent(dependent: dependent)
                self.navigationController?.popViewController(animated: true)
            } catch {
                self.handleErrors(error: error)
            }
        }
    }

这不起作用

 func updateDependent(dependent: Dependent, pass: String, newPass: String? = nil, completion: @escaping (Result<EmptyResponse>) -> Void) {
        var url = baseURL
        url.appendPathComponent("/api/dependent/cpf/\(dependent.dependentId)")
        let params = dependent.updateParams(pass: pass, newPass: newPass)
        let data = try! JSONSerialization.data(withJSONObject: params!, options: [])
        print(try! JSONSerialization.jsonObject(with: data, options: .allowFragments))
        request(url: url, method: .put, isAuth: true, params: params, completion: completion)
    }

谁可以给光?

0 个答案:

没有答案