0001    // The MIT License (MIT)
0002    
0003    // Copyright (c) 2015 JohnLui <wenhanlv@gmail.com> https://github.com/johnlui
0004    
0005    // Permission is hereby granted, free of charge, to any person obtaining a copy
0006    // of this software and associated documentation files (the "Software"), to deal
0007    // in the Software without restriction, including without limitation the rights
0008    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0009    // copies of the Software, and to permit persons to whom the Software is
0010    // furnished to do so, subject to the following conditions:
0011    
0012    // The above copyright notice and this permission notice shall be included in all
0013    // copies or substantial portions of the Software.
0014    
0015    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0018    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0020    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0021    // SOFTWARE.
0022    //
0023    //  JSONND.swift
0024    //  JSONNeverDie
0025    //
0026    //  Created by 吕文翰 on 15/10/7.
0027    //
0028    
0029    import Foundation
0030    
0031    public struct JSONND
JSONND+ArrayLiteralConvertible.swift:32
extension JSONND: ArrayLiteralConvertible {
JSONND+DictionaryLiteralConvertible.swift:32
extension JSONND: DictionaryLiteralConvertible {
JSONND.swift:36
    public static func initWithData(data: NSData) -> JSONND! {
JSONND.swift:38
            return JSONND(data: try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments))
JSONND.swift:41
            if JSONND.debug { NSLog(e.localizedDescription); }
JSONND.swift:42
            return JSONND(data: nil)
JSONND.swift:46
        let j: JSONND = [any]
JSONND.swift:64
                return JSONND(data: value)
JSONND.swift:66
                if JSONND.debug { NSLog("JSONNeverDie: No such key '\(index)'"); }
JSONND.swift:69
        return JSONND(data: nil)
JSONND.swift:144
                    var result = Array<JSONND>()
JSONND.swift:146
                        result.append(JSONND(data: i))
JSONND.swift:140
    public var array: [JSONND]? {
JSONND.swift:155
    public var arrayValue: [JSONND] {
JSONNDModel.swift:33
    public var JSONNDObject: JSONND!
JSONNDModel.swift:35
    public required init(JSONNDObject json: JSONND) {
Pitaya.swift:177
    public func responseJSON(callback: ((json: JSONND, response: NSHTTPURLResponse?) -> Void)?) {
Pitaya.swift:179
            var json = JSONND()
Pitaya.swift:181
                json = JSONND.initWithData(d)
{ 0032 0033 public static var debug
JSONND.swift:41
            if JSONND.debug { NSLog(e.localizedDescription); }
JSONND.swift:66
                if JSONND.debug { NSLog("JSONNeverDie: No such key '\(index)'"); }
= false 0034 0035 public var data
JSONND.swift:47
        self.data = j.arrayValue.first != nil ? j.arrayValue.first!.data : nil
JSONND.swift:47
        self.data = j.arrayValue.first != nil ? j.arrayValue.first!.data : nil
JSONND.swift:50
        self.data = data
JSONND.swift:62
        if let jsonDictionary = self.data as? Dictionary<String, AnyObject> {
JSONND.swift:79
                if let _ = self.data {
JSONND.swift:80
                    let d = try NSJSONSerialization.dataWithJSONObject(self.data, options: .PrettyPrinted)
JSONND.swift:102
            return self.data?.integerValue
JSONND.swift:112
            return self.data?.floatValue
JSONND.swift:122
            return self.data as? String
JSONND.swift:132
            return self.data as? Bool
JSONND.swift:142
            if let _ = self.data {
JSONND.swift:143
                if let arr = self.data as? Array<AnyObject> {
: AnyObject! 0036 public static func initWithData
Pitaya.swift:181
                json = JSONND.initWithData(d)
(data: NSData) -> JSONND! { 0037 do { 0038 return JSONND(data: try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)) 0039 } catch let error as NSError { 0040 let e = NSError(domain: "JSONNeverDie.JSONParseError", code: error.code, userInfo: error.userInfo) 0041 if JSONND.debug { NSLog(e.localizedDescription); } 0042 return JSONND(data: nil) 0043 } 0044 } 0045 private init
JSONND.swift:56
        self.init(any: dictionary)
JSONND.swift:59
        self.init(any: array)
(any: AnyObject) { 0046 let j: JSONND = [any] 0047 self.data = j.arrayValue.first != nil ? j.arrayValue.first!.data : nil 0048 } 0049 init
JSONND+ArrayLiteralConvertible.swift:34
        self.init(data: elements)
JSONND+DictionaryLiteralConvertible.swift:34
        self.init(data: elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in
JSONND.swift:38
            return JSONND(data: try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments))
JSONND.swift:42
            return JSONND(data: nil)
JSONND.swift:53
        self.init(data: nil)
JSONND.swift:64
                return JSONND(data: value)
JSONND.swift:69
        return JSONND(data: nil)
JSONND.swift:146
                        result.append(JSONND(data: i))
(data: AnyObject!) { 0050 self.data = data 0051 } 0052 public init
Pitaya.swift:179
            var json = JSONND()
() { 0053 self.init(data: nil) 0054 } 0055 public init(dictionary: [String: AnyObject]) { 0056 self.init(any: dictionary) 0057 } 0058 public init(array: [AnyObject]) { 0059 self.init(any: array) 0060 } 0061 public subscript
JSONNDModel.swift:42
                let json = self.JSONNDObject[key]
(index: String) -> JSONND { 0062 if let jsonDictionary = self.data as? Dictionary<String, AnyObject> { 0063 if let value = jsonDictionary[index] { 0064 return JSONND(data: value) 0065 } else { 0066 if JSONND.debug { NSLog("JSONNeverDie: No such key '\(index)'"); } 0067 } 0068 } 0069 return JSONND(data: nil) 0070 } 0071 0072 @available (*, unavailable, renamed="RAW") 0073 public var jsonString: String? { 0074 return "" 0075 } 0076 public var RAW
JSONND.swift:97
            return self.RAW ?? ""
JSONNDModel.swift:67
            return self.JSONNDObject?.RAW
: String? { 0077 get { 0078 do { 0079 if let _ = self.data { 0080 let d = try NSJSONSerialization.dataWithJSONObject(self.data, options: .PrettyPrinted) 0081 return NSString(data: d, encoding: NSUTF8StringEncoding) as? String 0082 } 0083 return nil 0084 } catch { 0085 // can not test Errors here. 0086 // It seems that NSJSONSerialization.dataWithJSONObject() method dose not support do-try-catch in Swift 2 now. 0087 return nil 0088 } 0089 } 0090 } 0091 @available (*, unavailable, renamed="RAWValue") 0092 public var jsonStringValue: String { 0093 return "" 0094 } 0095 public var RAWValue: String { 0096 get { 0097 return self.RAW ?? "" 0098 } 0099 } 0100 public var int
JSONND.swift:107
            return self.int ?? 0
: Int? { 0101 get { 0102 return self.data?.integerValue 0103 } 0104 } 0105 public var intValue
JSONNDModel.swift:48
                    valueWillBeSet = json.intValue
: Int { 0106 get { 0107 return self.int ?? 0 0108 } 0109 } 0110 public var float
JSONND.swift:117
            return self.float ?? 0.0
: Float? { 0111 get { 0112 return self.data?.floatValue 0113 } 0114 } 0115 public var floatValue
JSONNDModel.swift:50
                    valueWillBeSet = json.floatValue
: Float { 0116 get { 0117 return self.float ?? 0.0 0118 } 0119 } 0120 public var string
JSONND.swift:127
            return self.string ?? ""
: String? { 0121 get { 0122 return self.data as? String 0123 } 0124 } 0125 public var stringValue
JSONNDModel.swift:46
                    valueWillBeSet = json.stringValue
: String { 0126 get { 0127 return self.string ?? "" 0128 } 0129 } 0130 public var bool
JSONND.swift:137
            return self.bool ?? false
: Bool? { 0131 get { 0132 return self.data as? Bool 0133 } 0134 } 0135 public var boolValue
JSONNDModel.swift:52
                    valueWillBeSet = json.boolValue
: Bool { 0136 get { 0137 return self.bool ?? false 0138 } 0139 } 0140 public var array
JSONND.swift:157
            return self.array ?? [] 
: [JSONND]? { 0141 get { 0142 if let _ = self.data { 0143 if let arr = self.data as? Array<AnyObject> { 0144 var result = Array<JSONND>() 0145 for i in arr { 0146 result.append(JSONND(data: i)) 0147 } 0148 return result 0149 } 0150 return nil 0151 } 0152 return nil 0153 } 0154 } 0155 public var arrayValue
JSONND.swift:47
        self.data = j.arrayValue.first != nil ? j.arrayValue.first!.data : nil
JSONND.swift:47
        self.data = j.arrayValue.first != nil ? j.arrayValue.first!.data : nil
: [JSONND] { 0156 get { 0157 return self.array ?? [] 0158 } 0159 } 0160 } 0161