Json Value

Defined in framework ScanditCaptureCore

Warning

The deserialization API is not yet stable and will still change over the coming releases.

JSONValue
open class JSONValue : NSObject

Added in version 6.0.0

JSON representation for use with the Scandit Data Capture SDK. It provides a lot of convenience functions for deserialization of base classes. It also tracks the usage of properties to be able to later report those that were not used for deserialization (potentially because they were misspelled or are outdated).

init(string:)
convenience init(string: String)

Added in version 6.1.0

Returns a new JSON Value for the given json string. An exception is thrown if the string is not a valid JSON representation.

jsonString()
open func jsonString() -> String

Added in version 6.1.0

Returns the string representation of the JSON value.

asBOOL()
open func asBOOL() -> Bool

Added in version 6.1.0

Returns the value as a boolean. An exception is thrown if the conversion is not possible.

bool(forKey:)
open func bool(forKey key: String) -> Bool

Added in version 6.1.0

Returns the value for the given key as a boolean. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a boolean.

bool(forKey:default:)
open func bool(forKey key: String, default defaultValue: Bool) -> Bool

Added in version 6.1.0

Returns the value for the given key as a boolean. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a boolean.

asInteger()
open func asInteger() -> Int

Added in version 6.1.0

Returns the value as an integer. An exception is thrown if the conversion is not possible.

integer(forKey:)
open func integer(forKey key: String) -> Int

Added in version 6.1.0

Returns the value for the given key as an integer. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an integer.

integer(forKey:default:)
open func integer(forKey key: String, default defaultValue: Int) -> Int

Added in version 6.1.0

Returns the value for the given key as an integer. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an integer.

asCGFloat()
open func asCGFloat() -> CGFloat

Added in version 6.1.0

Returns the value as a float. An exception is thrown if the conversion is not possible.

cgFloat(forKey:)
open func cgFloat(forKey key: String) -> CGFloat

Added in version 6.1.0

Returns the value for the given key as a float. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a float.

cgFloat(forKey:default:)
open func cgFloat(forKey key: String, default defaultValue: CGFloat) -> CGFloat

Added in version 6.1.0

Returns the value for the given key as a float. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a float.

asString()
open func asString() -> String

Added in version 6.1.0

Returns the value as a string. An exception is thrown if the conversion is not possible.

string(forKey:)
open func string(forKey key: String) -> String

Added in version 6.1.0

Returns the value for the given key as a string. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a string.

string(forKey:default:)
open func string(forKey key: String, default defaultValue: String) -> String

Added in version 6.1.0

Returns the value for the given key as a string. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a string.

asColor()
open func asColor() -> UIColor

Added in version 6.1.0

Returns the value as a color. An exception is thrown if the conversion is not possible.

color(forKey:)
open func color(forKey key: String) -> UIColor

Added in version 6.1.0

Returns the value for the given key as a color. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a color.

color(forKey:default:)
open func color(forKey key: String, default defaultValue: UIColor) -> UIColor

Added in version 6.1.0

Returns the value for the given key as a color. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a color.

asBrush()
open func asBrush() -> Brush

Added in version 6.1.0

Returns the value as a Brush. An exception is thrown if the conversion is not possible.

brush(forKey:)
open func brush(forKey key: String) -> Brush

Added in version 6.1.0

Returns the value for the given key as a Brush. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a Brush.

brush(forKey:default:)
open func brush(forKey key: String, default defaultValue: Brush) -> Brush

Added in version 6.1.0

Returns the value for the given key as a Brush. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a Brush.

asFloatWithUnit()
open func asFloatWithUnit() -> FloatWithUnit

Added in version 6.1.0

Returns the value as a FloatWithUnit. An exception is thrown if the conversion is not possible.

floatWithUnit(forKey:)
open func floatWithUnit(forKey key: String) -> FloatWithUnit

Added in version 6.1.0

Returns the value for the given key as a FloatWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a FloatWithUnit.

floatWithUnit(forKey:default:)
open func floatWithUnit(forKey key: String, default defaultValue: FloatWithUnit) -> FloatWithUnit

Added in version 6.1.0

Returns the value for the given key as a FloatWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a FloatWithUnit.

asPointWithUnit()
open func asPointWithUnit() -> PointWithUnit

Added in version 6.1.0

Returns the value as a PointWithUnit. An exception is thrown if the conversion is not possible.

pointWithUnit(forKey:)
open func pointWithUnit(forKey key: String) -> PointWithUnit

Added in version 6.1.0

Returns the value for the given key as a PointWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a PointWithUnit.

pointWithUnit(forKey:default:)
open func pointWithUnit(forKey key: String, default defaultValue: PointWithUnit) -> PointWithUnit

Added in version 6.1.0

Returns the value for the given key as a PointWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a PointWithUnit.

asMarginsWithUnit()
open func asMarginsWithUnit() -> MarginsWithUnit

Added in version 6.1.0

Returns the value as a MarginsWithUnit. An exception is thrown if the conversion is not possible.

marginsWithUnit(forKey:)
open func marginsWithUnit(forKey key: String) -> MarginsWithUnit

Added in version 6.1.0

Returns the value for the given key as a MarginsWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a MarginsWithUnit.

marginsWithUnit(forKey:default:)
open func marginsWithUnit(forKey key: String, default defaultValue: MarginsWithUnit) -> MarginsWithUnit

Added in version 6.1.0

Returns the value for the given key as a MarginsWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a MarginsWithUnit.

asArray()
open func asArray() -> JSONValue

Added in version 6.1.0

Returns the value if it is an array. An exception is thrown if the conversion is not possible.

array(forKey:)
open func array(forKey key: String) -> JSONValue

Added in version 6.1.0

Returns the value for the given key as an array. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an array.

array(forKey:default:)
open func array(forKey key: String, default defaultValue: JSONValue) -> JSONValue

Added in version 6.1.0

Returns the value for the given key as an array. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an array.

count()
open func count() -> UInt

Added in version 6.1.0

The size of the array. An exception is thrown if this JSON value is not an array.

atIndex(_:)
open func atIndex(_ index: UInt) -> JSONValue

Added in version 6.1.0

Returns the value for the given index. An exception is thrown if this JSON Value is not an array or the given index is out of bounds.

asObject()
open func asObject() -> JSONValue

Added in version 6.1.0

Returns the value if it is an object. An exception is thrown if the conversion is not possible.

object(forKey:)
open func object(forKey key: String) -> JSONValue

Added in version 6.1.0

Returns the value for the given key as an object. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an object.

object(forKey:default:)
open func object(forKey key: String, default defaultValue: JSONValue) -> JSONValue

Added in version 6.1.0

Returns the value for the given key as an object. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an object.

containsKey(_:)
open func containsKey(_ key: String) -> Bool

Added in version 6.1.0

Returns whether a value for the given key exists. An exception is thrown if this JSON Value is not an object.

absolutePath
open var absolutePath: String { get }

Added in version 6.1.0

The path from the root to this JSON value.

isUsed
open var isUsed: Bool { get, set }

Added in version 6.1.0

Whether this JSON value was used during deserialization.

asTimeinterval()
open func asTimeinterval() -> TimeInterval

Added in version 6.16.0

Returns the current value as a value representing a TimeInterval.

timeinterval(forKey:)
open func timeinterval(forKey key: String) -> TimeInterval

Added in version 6.16.0

Returns the value for the given key as a TimeInterval.

keys()
open func keys() -> Set<String>

Added in version 6.16.0

Returns the keys of the current value if any.

removeKeys(_:)
open func removeKeys(_ keysToRemove: Set<String>) -> Void

Added in version 6.16.0

Removes the given keys from the current value.

containsArray(withKey:)
open func containsArray(withKey key: String) -> Bool

Added in version 6.16.0

Determines whether the current value is an object and contains an array with the given key.

containsObject(withKey:)
open func containsObject(withKey key: String) -> Bool

Added in version 6.16.0

Determines whether the current value is an object and contains an object with the given key.

renameKey(_:targetKeyName:)
open func renameKey(_ originalKeyName: String, targetKeyName: String) -> Void

Added in version 6.16.0

Renames the given key to the target key name if the given key name is present.