Merge branch 'feature/TrialFraud-DEVAO-1533' into 'develop'
TrialFraud extension additions See merge request BPHV_MIPS/mvm_core!194
This commit is contained in:
commit
7f57d493f6
@ -25,6 +25,15 @@ extension Encodable {
|
||||
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? {
|
||||
guard let json = self.toJSON(),
|
||||
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 {
|
||||
public func toJSONObject() throws -> JSONDictionary {
|
||||
let encoded = try JSONEncoder().encode(self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user