I wrote the following function to do a GET request inside of my macOS app using Alamofire:
func getContent(room: String) -> String {
let scriptUrl = "https://klipped.in/api/\(room)"
Alamofire.request(scriptUrl).responseJSON { response in
if let json = response.result.value {
print("\(json)") // serialized json response
}
}
return "This should return the value of \"content\" in the json response"
}
I now want to parse the json in the most efficient way possible. I googled around ways to do this, but every solution I found seems overly complicated or doesn't run because of type problems.
Is there a simple way in Swift to access the values inside of a JSON without creating a Struct for every response? I'm thinking about something along the lines of:
get-json-value(json, "content")
That returns the string value of "content" inside of a json and null if it doesn't exist.