JSON
public struct JSON
Undocumented
-
Creates a JSON using the data.
Declaration
Swift
public init(data: Data, options opt: JSONSerialization.ReadingOptions = []) throws
Parameters
data
The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary
opt
The JSON serialization reading options.
[]
by default.Return Value
The created JSON
-
Creates a JSON object
Note
this does not parse aString
into JSON, instead useinit(parseJSON: String)
Declaration
Swift
public init(_ object: Any)
Parameters
object
the object
Return Value
the created JSON object
-
Parses the JSON string into a JSON object
Declaration
Swift
public init(parseJSON jsonString: String)
Parameters
json
the JSON string
Return Value
the created JSON object
-
Creates a JSON from JSON string
Declaration
Swift
public static func parse(_ json: String) -> JSON
Parameters
string
Normal json string like ‘{
a
:b
}’Return Value
The created JSON
-
Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, present values getting overwritten, array values getting appended and nested JSONs getting merged the same way.
Throws
throwsErrorWrongType
if the other JSONs differs in type on the top level.Declaration
Swift
public mutating func merge(with other: JSON) throws
Parameters
other
The JSON which gets merged into this JSON
-
Merges another JSON into this JSON and returns a new JSON, whereas primitive values which are not present in this JSON are getting added, present values getting overwritten, array values getting appended and nested JSONS getting merged the same way.
Throws
throwsErrorWrongType
if the other JSONs differs in type on the top level.Declaration
Swift
public func merged(with other: JSON) throws -> JSON
Parameters
other
The JSON which gets merged into this JSON
Return Value
New merged JSON
-
JSON type, fileprivate setter
Declaration
Swift
public fileprivate(set) var type: Type = .null
-
Error in JSON, fileprivate setter
Declaration
Swift
public fileprivate(set) var error: SwiftyJSONError?
-
Object in JSON
Declaration
Swift
public var object: Any
-
Undocumented
Declaration
Swift
public static var null: JSON
-
Find a json in the complex data structures by using array of Int and/or String as path.
let json = JSON[data] let path = [9,
list
,person
,name
] let name = json[path]The same as: let name = json[9][
list
][person
][name
]Declaration
Swift
public subscript(path: [JSONSubscriptType]) -> JSON
Parameters
path
The target json’s path. Example:
Return Value
Return a json found by the path or a null json with error
-
Find a json in the complex data structures by using array of Int and/or String as path.
let name = json[9,
list
,person
,name
]The same as: let name = json[9][
list
][person
][name
]Declaration
Swift
public subscript(path: JSONSubscriptType...) -> JSON
Parameters
path
The target json’s path. Example:
Return Value
Return a json found by the path or a null json with error
-
Declaration
Swift
public init(stringLiteral value: StringLiteralType)
-
Declaration
Swift
public init(extendedGraphemeClusterLiteral value: StringLiteralType)
-
Declaration
Swift
public init(unicodeScalarLiteral value: StringLiteralType)
-
Declaration
Swift
public init(integerLiteral value: IntegerLiteralType)
-
Declaration
Swift
public init(booleanLiteral value: BooleanLiteralType)
-
Declaration
Swift
public init(floatLiteral value: FloatLiteralType)
-
Declaration
Swift
public init(dictionaryLiteral elements: (String, Any)...)
-
Declaration
Swift
public init(arrayLiteral elements: Any...)
-
Declaration
Swift
public init(nilLiteral: ())
-
Declaration
Swift
public init?(rawValue: Any)
-
Declaration
Swift
public var rawValue: Any
-
Undocumented
Declaration
Swift
public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data
-
Undocumented
Declaration
Swift
public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String?
-
Undocumented
Declaration
Swift
public func rawString(_ options: [writingOptionsKeys: Any]) -> String?
-
Declaration
Swift
public var description: String
-
Declaration
Swift
public var debugDescription: String
-
Undocumented
Declaration
Swift
public var array: [JSON]?
-
Undocumented
Declaration
Swift
public var arrayValue: [JSON]
-
Undocumented
Declaration
Swift
public var arrayObject: [Any]?
-
Undocumented
Declaration
Swift
public var dictionary: [String : JSON]?
-
Undocumented
Declaration
Swift
public var dictionaryValue: [String : JSON]
-
Undocumented
Declaration
Swift
public var dictionaryObject: [String : Any]?
-
Undocumented
Declaration
Swift
public var bool: Bool?
-
Undocumented
Declaration
Swift
public var boolValue: Bool
-
Undocumented
Declaration
Swift
public var string: String?
-
Undocumented
Declaration
Swift
public var stringValue: String
-
Undocumented
Declaration
Swift
public var number: NSNumber?
-
Undocumented
Declaration
Swift
public var numberValue: NSNumber
-
Undocumented
Declaration
Swift
public var null: NSNull?
-
Undocumented
Declaration
Swift
public func exists() -> Bool
-
Undocumented
Declaration
Swift
public var url: URL?
-
Undocumented
Declaration
Swift
public var double: Double?
-
Undocumented
Declaration
Swift
public var doubleValue: Double
-
Undocumented
Declaration
Swift
public var float: Float?
-
Undocumented
Declaration
Swift
public var floatValue: Float
-
Undocumented
Declaration
Swift
public var int: Int?
-
Undocumented
Declaration
Swift
public var intValue: Int
-
Undocumented
Declaration
Swift
public var uInt: UInt?
-
Undocumented
Declaration
Swift
public var uIntValue: UInt
-
Undocumented
Declaration
Swift
public var int8: Int8?
-
Undocumented
Declaration
Swift
public var int8Value: Int8
-
Undocumented
Declaration
Swift
public var uInt8: UInt8?
-
Undocumented
Declaration
Swift
public var uInt8Value: UInt8
-
Undocumented
Declaration
Swift
public var int16: Int16?
-
Undocumented
Declaration
Swift
public var int16Value: Int16
-
Undocumented
Declaration
Swift
public var uInt16: UInt16?
-
Undocumented
Declaration
Swift
public var uInt16Value: UInt16
-
Undocumented
Declaration
Swift
public var int32: Int32?
-
Undocumented
Declaration
Swift
public var int32Value: Int32
-
Undocumented
Declaration
Swift
public var uInt32: UInt32?
-
Undocumented
Declaration
Swift
public var uInt32Value: UInt32
-
Undocumented
Declaration
Swift
public var int64: Int64?
-
Undocumented
Declaration
Swift
public var int64Value: Int64
-
Undocumented
Declaration
Swift
public var uInt64: UInt64?
-
Undocumented
Declaration
Swift
public var uInt64Value: UInt64