Encodable
public extension Encodable
-
Encodes an
Encodable
object as a json string.Throws
If the object cannot be encoded to json.Declaration
Swift
func toJsonString(convertToSnakeCase: Bool = false, prettyPrinted: Bool = false) throws -> String
Parameters
convertToSnakeCase
Should camelCase keys be converted to snake_case? (default = false)
prettyPrinted
Should the output be prettyPrinted? (default = false)
Return Value
A json string.
-
Encodes an
Encodable
object as a json string.Throws
If the object cannot be encoded into a JSON object.Declaration
Swift
func toJsonData(convertToSnakeCase: Bool = false, prettyPrinted: Bool = false) throws -> Data
Parameters
convertToSnakeCase
Should camelCase keys be converted to snake_case? (default = false)
prettyPrinted
Should the output be prettyPrinted? (default = false)
Return Value
A Data object.
-
Encodes an
Encodable
object as a dictionary of type[String: Any]
.Declaration
Swift
func toDictionary() -> [String : Any]?
Return Value
A dictionary of type
[String: Any]
. -
Encodes an
Encodable
object as a array of type[Any]
.Declaration
Swift
func toArray() -> [Any]?
Return Value
A dictionary of type
[Any]
.