TrialFraud extension additions
This commit is contained in:
parent
e0d3bfb9e3
commit
3e06f6ee44
@ -25,6 +25,15 @@ extension Encodable {
|
|||||||
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONDictionary }
|
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? JSONDictionary }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func toJSONAny() throws -> [String: Any] {
|
||||||
|
let data = try self.encode()
|
||||||
|
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
|
||||||
|
guard let jsonAny = json as? [String: Any] else {
|
||||||
|
throw JSONError.error(message: "JSON Dictionary not found")
|
||||||
|
}
|
||||||
|
return jsonAny
|
||||||
|
}
|
||||||
|
|
||||||
public func toJSONString() -> String? {
|
public func toJSONString() -> String? {
|
||||||
guard let json = self.toJSON(),
|
guard let json = self.toJSON(),
|
||||||
let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted),
|
let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted),
|
||||||
|
|||||||
@ -119,6 +119,13 @@ extension Dictionary where Key == String, Value == Any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Dictionary where Key == String, Value == AnyHashable {
|
||||||
|
public func toJSONValue() throws -> [String: JSONValue] {
|
||||||
|
let data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted)
|
||||||
|
return try JSONDecoder().decode([String:JSONValue].self, from: data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension Dictionary where Key == String, Value == JSONValue {
|
extension Dictionary where Key == String, Value == JSONValue {
|
||||||
public func toJSONObject() throws -> JSONDictionary {
|
public func toJSONObject() throws -> JSONDictionary {
|
||||||
let encoded = try JSONEncoder().encode(self)
|
let encoded = try JSONEncoder().encode(self)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user