从结构解码URL

时间:2019-05-28 05:42:37

标签: swift collectionview decodable

尝试从JSON文件/ API中读取网址,但获得零值

  

错误:[] JSON错误:技能2019-05-28 13:38:03.631671 + 0800   技能[465:28939] [声明]不能通过asCopy = NO调用   非主线程。 2019-05-28 13:38:03.631809 + 0800技能[465:28939]   [Assert]无法在非主线程上使用asCopy = NO调用。   2019-05-28 13:38:03.631988 + 0800技能[465:28939] [声明]不能   在非主线程上使用asCopy = NO调用。 2019-05-28   13:38:03.632111 + 0800技能[465:28939] [声明]无法与   非主线程上的asCopy = NO。 2019-05-28 13:40:12.455115 + 0800   技能[465:29290] [BoringSSL] nw_protocol_boringssl_error(1584)   [C1.1:2] [0x11ff0d350]较低的协议栈错误:54 2019-05-28   13:40:12.456622 + 0800 lara [465:29290] TIC读取状态[1:0x283b9ac40]:   1:54 2019-05-28 13:40:12.456755 + 0800 lara [465:29290] TIC读取状态   [1:0x283b9ac40]:1:54

import UIKit
import Foundation

struct getSkills: Codable {
    let TSCTtopicID: Int
    let TSCTtopicName, TSCTtopicDescription, Status: String
    let TSCTMemorabilia: String
    let TSCTzipFile: URL

   enum CodingKeys: String, CodingKey {
        case TSCTtopicID = "TSCTtopicID"
        case TSCTtopicName = "TSCTtopicName"
        case TSCTtopicDescription = "TSCTtopicDescription"
        case Status = "Status"
        case TSCTMemorabilia = "TSCTMemorabilia"
        case TSCTzipFile = "File"
    }

}

    func getSkillsDetails(completed: @escaping () -> ()) {
        let tid = String(skillID!)
        let siebelid = sID
        let rootLink = "https://skills.com/iOS/getsk.php?"
        let url = URL (string: rootLink + "sid=" + siebelid + "&tid=" + tid)

        URLSession.shared.dataTask(with: url!) {(data, response, error) in
            if error == nil {
                do {
                    self.getSkillsInfo = try JSONDecoder().decode([getSkills].self, from: data!)
                    print(self.getSkillsInfo)
                 // self.getName()
                    print(self.trainingTitle)
                    DispatchQueue.main.async {
                         self.trainingTable.reloadData()
                        completed()
                    }
                } catch {
                    print("JSON Error: Skills")
                    self.handleJSONErrorAlert()
                }
            } else {
                self.handleNoNetAlert()
            }
            }.resume()
    }

0 个答案:

没有答案