目录
目录README.md

JSON Fragment Decoding

A JSONDecoder extension to allow decoding JSON fragments.

Usage

Simply pass allowFragments: true to a JSONDecoder.decode(_:from:) call, and you’ll be able to decode JSON fragments:

import Foundation
import JSONFragmentDecoding

let data = Data("10".utf8)

let decoded = try JSONDecoder().decode(Int.self, from: data, allowFragments: true)
print(decoded) // 10

Installation

Honestly it’s so lightweight that you could just drop /Sources/JSONFragmentDecoding/JSONFragmentDecoding.swift into your project and be on your way.

Swift PM

Add the following dependancy to your Package.swift file:

dependencies: [
  .package(url: "https://github.com/hamishknight/JSON-Fragment-Decoding.git", from: "0.1.0")
],

and then add the dependancy to any targets that need to use it:

targets: [
  .target(
    name: "SomeTarget",
    dependencies: ["JSON-Fragment-Decoding"]),
]

Carthage

Add the following to your Cartfile:

github "hamishknight/JSON-Fragment-Decoding" ~> 0.1
关于
43.0 KB
邀请码