Latest 1.2.5
Homepage http://github.com/keefmoon/JSONNode
License MIT
Platforms ios 8.0, tvos 9.0, osx 10.9, watchos 2.0, requires ARC
Authors

no README.md available

Latest podspec

{
    "name": "JSONNode",
    "version": "1.2.5",
    "summary": "A simple, Swifty way to interact with JSON",
    "description": "# JSONNodennA simple, Swifty way to interact with JSON.nnJSONNode is simple, useful, and under 150 lines of code.nn## Advantage over traditional JSON handlingnnLet's take the response from the ImgFlip Meme APInn```JSONn{n    "success": true,n    "data": {n        "memes": [n            {n                "id": "61579",n                "name": "One Does Not Simply",n                "url": "http://i.imgflip.com/1bij.jpg",n                "width": 568,n                "height": 335n            },n            {n                "id": "101470",n                "name": "Ancient Aliens",n                "url": "http://i.imgflip.com/26am.jpg",n                "width": 500,n                "height": 437n            }n        ]n    }n}n```nnTo retrieve the name for the first meme, you would do the following:nn```Swiftnvar jsonObject = try! JSONSerialization.jsonObject(with: jsonData, options: [.allowFragments])nnguardn    let jsonDictionary = jsonObject as? [String: Any],n    let dataDictionary = jsonDictionary["data"] as? [String: Any],n    let memesArray = dataDictionary["memes"] as? [[String: Any]],n    let firstMeme = memesArray.first,n    let memeName = firstMeme["name"] as? String else {nn        fatalError()n}nnprint(memeName)n```nnWith JSONNode this becomes the following:nn```Swiftnvar jsonNode = try! JSONNode(data: jsonData)nguard let name = jsonNode["data"]["memes"][0]["name"].string else { fatalError() }nnprint(name)n```nn## How it worksnnTypically when JSON is deserialised, it is turned into nested arrays and dictionary, and since these collections need a type and the JSON could contain any of multiple types, the non-specific `Any` protocol is used.nnThis is not a true representation of the situation though. There can't be "anything" in the collection. Each node in the JSON structure can only be one of the following:n- Stringn- Booleann- Integern- Floating point numbern- Array containing something in this listn- Dictionary with a string key and value as something in this listnnWith this finite list of possible values for a JSON node, a enum is the best way to represent that. Inspiration was taken from the way that Swift Playgrounds passes information been the playground page and the live view.nn## Requirementsnn- Swift 3n- Xcode 8nn## Integrationnn#### CocoaPodsnnYou can use [CocoaPods](http://cocoapods.org/) to install `JSONNode`by adding it to your `Podfile`:nn```rubynplatform :ios, '8.0'nuse_frameworks!nntarget 'MyApp' donpod 'JSONNode'nendn```nnNote that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0:nnn#### Manually (iOS 8+, OS X 10.9+)nnTo use this library in your project manually you may:nn1. for Projects, just drag JSONNode.swift to the project treen2. for Workspaces, include the whole JSONNode.xcodeproj",
    "homepage": "http://github.com/keefmoon/JSONNode",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Keith Moon": "[email protected]"
    },
    "social_media_url": "http://twitter.com/keefmoon",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0",
        "osx": "10.9",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/keefmoon/JSONNode.git",
        "tag": "1.2.5"
    },
    "source_files": [
        "JSONNode",
        "JSONNode/JSONNode/*.{swift}"
    ],
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "3.0"
    },
    "requires_arc": true,
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This