Sunshine-Rain / FaultToleranceJSONDecoder

A json decoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FaultToleranceJSONDecoder

A json decoder has fault tolerance. Most of codes are based on JSONDecoder.swift.

Dependency

  • SwiftyJSON

Usage

  • Install dependencies using cocoapods or carthage.
  • Drag Source Code to your project.
  • Use as swift JSONDecoder.
struct Landmark: Codable {
    var name: String
    var age: Int
    var isCommander: Bool
    
    enum CodingKeys: String, CodingKey {
        case name = "__name"
        case age = "age"
        case isCommander = "isCommander"
    }
}


let landmarkStr = """
{
    "__name" : "Hello",
    "age" : 18,
    "isCommander" : null
}
"""

let jsonDecoder = FaultToleranceJSONDecoder()
let model = try! jsonDecoder.decode(String.self, from: landmarkStr.data(using: .utf8)!)
print(model)

About

A json decoder


Languages

Language:Swift 100.0%