无法使用HandyJSON解析json(字符串)。错误(类型“字符串”不符合协议“ HandyJSON”)

时间:2019-06-28 17:10:51

标签: json swift xcode

我开始研究IOS,但有一个问题。 我正在尝试使用HandyJSON获取Json(String),但出现错误并且不明白我需要做什么,请告诉我。使用X代码10

func updateMedicalHelpStatus(username: String, password: String, access_token: String, status: Int) {
        AF.request(MainApi.feedsListBegin, parameters: ParametersApi.parametersTokenStatus(access_token: access_token, status: status), encoding:
            URLEncoding.default, headers: HTTPHeadersApi.headersLoginPassword(username: username, password: password)).responseJSON {
                response in
                switch response.result {
                case .success:
                    do {
                        let jsonData = try JSONSerialization.data(withJSONObject: response.result.value, options: .prettyPrinted)
                        let reqJSONStr = String(data: jsonData, encoding: .utf8)
                        let jsonResponse = BaseResponse<String>.deserialize(from: reqJSONStr)

                        if jsonResponse?.success == true  {
                                self.view.updateMedicalHelpStatusSuccessfully()
                        } else{
                                self.view.error(message: "")
                        }
                    }
                    catch {
                        self.view.error(message: "\(error)")
                    }
                    break
                case .failure(let error):
                    self.view.error(message: "\(error)")
                }
        }
    }

import Foundation
import HandyJSON
class BaseResponse<T: HandyJSON>: BaseError{
    let success: Bool = false
    let body: T? = nil
    required init() {      
    }
}

enter image description here

0 个答案:

没有答案