Swift 基于 Codable 的 JSON 解析解决方案

1,122 阅读1分钟
原文链接: github.com

CI Status Version Carthage compatible License Platform

在标准库源码基础上做了改动,以解决 JSONDecoder 各种解析失败的问题,如键值不存在,值为 null,类型不一致。

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9.0+
  • Swift 4

Installation

CleanJSON is available through CocoaPods or Carthage. To install it, simply add the following line to your Podfile or Cartfile:

Podfile

pod 'CleanJSON'

Cartfile

github "Pircate/CleanJSON"

Import

import CleanJSON

Usage

let decoder = CleanJSONDecoder()
try decoder.decode(Model.self, from: data)

Author

Pircate, gao497868860@gmail.com

License

CleanJSON is available under the MIT license. See the LICENSE file for more info.