JSON

    Helper class for creating and parsing JSON data.

    JSON.swift:30
    class JSON

    The JSON enables all data types to be converted to and from a JSON string. This useful for serializing data to save to a file or send over the network.

    stringify(data:indent:sortKeys:fullPrecision:) is used to convert any data type into a JSON string.

    parse(jsonText:keepText:) is used to convert any existing JSON data into a Variant that can be used within Godot. If successfully parsed, use data to retrieve the Variant, and use typeof to check if the Variant’s type is what you expect. JSON Objects are converted into a GDictionary, but JSON data can be used to store GArrays, numbers, Strings and even just a boolean.

    Example

    Alternatively, you can parse string using the static parseString(jsonString:) method, but it doesn’t allow to handle errors.

    • Trailing commas in arrays or objects are ignored, instead of causing a parser error.

    • New line and tab characters are accepted in string literals, and are treated like their corresponding escape sequences \n and \t.

    • Numbers are parsed using String/toFloat() which is generally more lax than the JSON specification.

    • Certain errors, such as invalid Unicode sequences, do not cause a parser error. Instead, the string is cleansed and an error is logged to the console.

    Superclasses

    Citizens in SwiftGodot

    Conformances

    • protocol CustomStringConvertible

      A type with a customized textual representation.

    • protocol Equatable

      A type that can be compared for value equality.

    • protocol Hashable

      A type that can be hashed into a Hasher to produce an integer hash value.

    • protocol Identifiable<ID>

      A class of types whose instances hold the value of an entity with stable identity.

    • protocol VariantRepresentable

      Types that conform to VariantRepresentable can be stored directly in Variant with no conversion. These include all of the Variant types from Godot (for example GString, Rect, Plane), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.

    • protocol VariantStorable

      Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.

    Type members

    Instance members