Swift 2016-04-19 23:39
Swift JSON 解析类库 CaesarParser
回复:0 查看:4117 感兴趣:3 赞:0
CaesarParser 是一个 JSON 解析类库,用 Swift 编写。
示例代码:
enum Gender: Int { case Unknown = 0 case Male = 1 case Female = 2 } class Person: JSONDeserializable, JSONSerializable { var name: String? var age: Int? var birthday: Double? var weight: Float? var adult: Bool = false var gender: Gender = .Unknown var girlFriend: Person? var friends = [Person]() var luckyNumbers = [Int]() var favouredSingers = [String: Person]() var vips = [Int: Person]() var preferNumbers = [Int: Int]() var orientation = [Gender]() init(json: JSONDictionary) { name <-- json["name"] age <-- json["age"] birthday <-- json["birthday"] weight <-- json["weight"] adult <-- json["adult"] gender <-- json["gender"] girlFriend <-- json["girlFriend"] friends <-- json["friends"] luckyNumbers <-- json["luckyNumbers"] favouredSingers <-- json["favouredSingers"] vips <-- json["vips"] preferNumbers <-- json["preferNumbers"] orientation <-- json["orientation"] } func toJSONObject() -> JSONObject { var json = JSONDictionary() name --> json["name"] age --> json["age"] birthday --> json["birthday"] weight --> json["weight"] adult --> json["adult"] gender --> json["gender"] girlFriend --> json["girlFriend"] friends --> json["friends"] luckyNumbers --> json["luckyNumbers"] favouredSingers --> json["favouredSingers"] vips --> json["vips"] preferNumbers --> json["preferNumbers"] orientation --> json["orientation"] return json } }
相关开源代码
EFIconFont: 一个用 Swift 实现的 IconFont 封装
Swift Zip文件压缩与解压框架
EFResume - 一个普通的 Swift 简历模板
Swift 优雅的定时器及执行工具库 Each
Swift 解析、格式化及验证国际电话号码工具库 PhoneNumberKit
Swift 版 FlatBuffers(跨平台序列化库)FlatBuffersSwift
Swift 编写的 Github API 客户端 Github.swift
Swift OAuth授权库 SwiftyOAuth
Swift 音频处理库 TempiFFT
iOS通知中心封装库SwiftNotificationCenter