JSONNeverDie aims to be a user friendly JSON encoder / decoder for iOS written with pure Swift which never dies.
- supports all types: Int, Float, Bool, String, Array
- user friendly: Xcode can prompt all available types
- provides both Optional-type(Int?) and Original-type(Int)
- well tested
- iOS 7.0+
- Xcode 7
import JSONNeverDie
parse a JSON from network and get a string:
let data = NSData(contentsOfURL: NSURL(string: "http://httpbin.org/get?hello=world")!)!
let json = JSONND.initWithData(data)
print(json["args"]["hello"].stringValue)
let data = NSData()
// init from NSData
let json = JSONND.initWithData(data)
// init from Array
let jsonArray: JSONND = ["hello", "world", 100]
// init from Dictionary
let jsonDictionary: JSONND = ["hello": "world", "hey": "guys"]
let value = json["key"].int
let value = json["key"].intValue
let value = json["key"].string
let value = json["key"].stringValue
let value = json["key"].float
let value = json["key"].floatValue
let value = json["key"].bool
let value = json["key"].boolValue
let value = json["key"].array
let value = json["key"].arrayValue
// more than one level
let value = json["key"]["key1"]["key2"].int
if let jsonArray = json["array"].array {
for jsonItem in jsonArray {
let value = jsonItem["key"].int
}
}
// or just
let value = json["array"].arrayValue[0]["key"].int
let string = json.jsonString
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate JSONNeverDie into your Xcode project using Carthage, specify it in your Cartfile:
github "JohnLui/JSONNeverDie"
Then fetch and build JSONNeverDie:
carthage update
At last, add it to "Embedded Binaries" in the general panel use the "Add Other..." button. The JSONNeverDie.framework binary file is lying in ./Carthage/Build/iOS
directory.
git submodule add https://github.com/johnlui/JSONNeverDie.git
open JSONNeverDie
then drag JSONNeverDie.xcodeproj to your Project, that's it!
If you want to run your project on device with JSONNeverDie, just go to PROJECT->TARGETS->[your project name]->General->Embedded Binaries, click ๏ผ, select JSONNeverDie.frameWork and click "Add".
Drag JSONNeverDie/JSONNeverDie.swift
into your project.
##Contribution
You are welcome to fork and submit pull requests.
##License
JSONNeverDie is open-sourced software licensed under the MIT license.