Skip to content
Fast conversion between JSON and model in Swift.
Swift Other
  1. Swift 98.4%
  2. Other 1.6%
Branch: master
Clone or download

README.md

KakaJSON

pod SwftPM compatible platforms

Fast conversion between JSON and model in Swift.

中文教程

Integration

CocoaPods

pod 'KakaJSON', '~> 1.2.1' 

Swift Package Manager

KakaJSON support Swift Package Manager from version 1.2.0. To use Swift Package Manager, you should update to Xcode 11.

  • Open your project.
  • Click File tab
  • Select Swift Packages
  • Add Package Dependency, enter KakaJSON repo's URL

Or you can login Xcode with your GitHub account. just search KakaJSON.

Usages

JSON To Model

struct Cat: Convertible {
    var name: String = ""
    var weight: Double = 0.0
}

let json: [String: Any] = [
    "name": "Miaomiao",
    "weight": 6.66
]

let cat = json.kk.model(Cat.self)
// let cat = model(from: json, Cat.self)

Model To JSON

struct Car: Convertible {
    var name: String = "Bently"
    var new: Bool = true
    var age: Int = 10
    var weight: Double = 0.1234567890123456
    var height: Decimal = 0.123456789012345678901234567890123456789
    var price: NSDecimalNumber = 0.123456789012345678901234567890123456789
    var minSpeed: Double = 66.66
    var maxSpeed: NSNumber = 77.77
}

let car = Car()
let json = car.kk.JSONObject()
let jsonString = car.kk.JSONString()
// let json = JSONObject(from: car)
// let jsonString = JSONString(from: car)

More documentation will be coming out soon....

You can’t perform that action at this time.