Swift 封装器 Jasoom

码农软件 · 软件分类 · 其他(Others) · 2019-07-17 16:29:33

软件介绍

Jasoom 是一个使用方便,类型安全 的NSJSONSerialization 
 Swift 封装器。

JSON 解析:

do {
    let json = try JSON.parseData(data)

    if json["name"].isUndefined {
        throw .MissingName
    }

    if json["info"]["age"].isUndefined {
        throw .MissingAge
    }

    let model = MyModel(
        name: json["name"].stringValue!
        age: json["info"]["age"].intValue!
        married: json["status"]["married"].boolValue ?? false
        firstCar: json["cars"][0].stringValue ?? ""
    )
}
catch {
    // Handle error
}

JSON 生成:

var object = JSON.object()
object["name"] = .String("Bob Smith")
object["info"] = JSON.object()
object["info"]["age"] = .Number(10)
object["status"] = JSON.object()
object["status"]["married"] = .Number(true)
object["cars"] = JSON.array()
object["cars"].append(.String("Ford Mustang"))

do {
    let data = try object.generateData()
}
catch {
    // Handle error
}

本文地址:https://codercto.com/soft/d/10342.html

The Little Typer

The Little Typer

Daniel P. Friedman、David Thrane Christiansen、Duane Bibby、Robert Harper、Conor Mcbride / MIT Press / 2018-10-16 / GBP 30.00

An introduction to dependent types, demonstrating the most beautiful aspects, one step at a time. A program's type describes its behavior. Dependent types are a first-class part of a language, and are......一起来看看 《The Little Typer》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具