Coder Social home page Coder Social logo

jsonneverdie's Introduction

JSONNeverDie Platform License Carthage compatible

JSONNeverDie aims to be a user friendly JSON encoder / decoder for iOS written with pure Swift which never dies.

Features

  • 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

Requirements

  • iOS 7.0+
  • Xcode 7

Use

import

import JSONNeverDie

basic example

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)

generate a JSONND object

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"]

get values

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

deal with array

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

Xcode can prompt all available types

pic

get raw string from a JSONND object

let string = json.jsonString

Installation

Carthage

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.

Manually

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".

Source File

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.

jsonneverdie's People

Contributors

johnlui avatar

Watchers

James Cloos avatar 杜永超(Eddy Du) avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.