swift封装Moya请求库后手动解析数据

释放双眼,带上耳机,听听看~!

封装了个网络请求库、但是想要手动解析、调出了方法、需要处理的是response中的data数据了

NetWorking是自己封装的类的名字

let ApiProvider = MoyaProvider<NetWorking>(requestClosure:timeoutClosure)

  • let idArr:[String] = ["77","73" ,"74" ,"76" ,"64" ,"67" ,"68","70","72"]
    let count:Int = Int(arc4random())%Int(idArr.count)
    //基础请求后 手动解析
    ApiProvider.request(.RoomStateInfo(roomID: idArr[count])) { (result) in
    switch result{
    case let .success(success):
    do {
    let json:[String:Any] = try JSONSerialization.jsonObject(with: success.data, options: .mutableContainers) as! [String : Any]
    let code = json["code"] as! NSNumber
    let msg:String = json["msg"] as! String
    if Int(code) != 200{
    ProgressHUD.showError(msg)
    }else{
    let datas:[String:Any] = json["data"] as! [String : Any]
    self.infoDic = datas
    self.createMainView()
    }
    } catch  {
    }
    case let .failure(error):
    ProgressHUD.showError(error.errorDescription as? String)
    print("(error)")
    }}

人已赞赏
iOS文章

iPhone固件下载地址

2020-4-8 15:18:01

iOS文章

swift基础

2020-4-8 16:33:12

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索