Closed edasque closed 7 years ago
You can do what you're describing like so:
let JSONdoc_as_string = "[\"One\",\"True\",\"Ring\"]"
do {
let json = try JSON(jsonString: JSONdoc_as_string)
let stringArray = try json.getArray()
XCTAssertTrue(stringArray == ["One", "True", "Ring"], "String arrays should match")
} catch {
print("Failure: \(error)")
}
path
is a variadic parameter:
public func getArray(at path: JSONPathType...) throws -> [JSON] {
return try JSON.getArray(from: value(at: path))
}
This allows you to pass nothing to it, which can be used to grab something at the top level.
Just before 3.0 was released, https://github.com/bignerdranch/Freddy/issues/211 highlighted the use of JSON.arrayOf or JSON.array without an at: parameter but in 3.0 I can't find them.
What am I missing?