added toJSONArray
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5ca22837bf
commit
316c0a04ae
@ -34,6 +34,15 @@ extension Encodable {
|
|||||||
return jsonAny
|
return jsonAny
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func toJSONArray() throws -> [Any] {
|
||||||
|
let data = try self.encode()
|
||||||
|
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
|
||||||
|
guard let jsonArray = json as? [Any] else {
|
||||||
|
throw JSONError.error(message: "JSON Array not found")
|
||||||
|
}
|
||||||
|
return jsonArray
|
||||||
|
}
|
||||||
|
|
||||||
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),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user