项目作者: tris-code

项目描述 :
JSON written in Swift with Stream/Codable support
高级语言: Swift
项目地址: git://github.com/tris-code/json.git
创建时间: 2019-04-05T00:04:36Z
项目社区:https://github.com/tris-code/json

开源协议:The Unlicense

下载


JSON

Fastest JSON implementation written in Swift.

Package.swift

  1. .package(url: "https://github.com/swiftstack/json.git", .branch("dev"))

Usage

Convenience API

  1. let bytes = JSON.encode(Model())
  2. let model = JSON.decode(Model.self, from: bytes)

Streaming API

  1. let output = OutputByteStream()
  2. JSON.encode(Model(), to: output)
  3. let input = InputByteStream(output.bytes)
  4. let model = JSON.decode(Model.self, from: input)

Encoder / Decoder + Streaming API

  1. let bytes = JSONEncoder().encode(Model())
  2. JSONEncoder().encode(Model(), to: stream)
  3. ...

JSON Value

  1. public struct JSON {
  2. public enum Value {
  3. case null
  4. case bool(Bool)
  5. case number(Number)
  6. case string(String)
  7. case array([JSON.Value])
  8. case object([String : JSON.Value])
  9. public enum Number {
  10. case int(Int)
  11. case uint(UInt)
  12. case double(Double)
  13. }
  14. }
  15. }

Performance

{"message":"Hello, World!"}

JSON.JSONEncoder: 934 644 tasks/sec

Foundation.JSONEncoder: 92 619 tasks/sec

JSON.JSONDecoder: 236 062 tasks/sec

Foundation.JSONDecoder: 226 515 tasks/sec

{"message":"\u3053\u3093\u306B\u3061\u306F\u4E16\u754C\uFF01"}

JSON.JSONDecoder: 179 440 tasks/sec

Foundation.JSONDecoder: 88 614 tasks/sec