В следующем коде вы можете увидеть все приложения, которые вы можете встретить при использовании json.
var responseDict: Any? = nil
let responseString : String? = "[\"For\", \"BW\", \"Fit\"]"
if let anEncoding = responseString?.data(using: .utf8) {
responseDict = try! JSONSerialization.jsonObject(with: anEncoding, options: .mutableContainers) as? Any
}
apiClientDidFinishWithResponse(response: responseDict)
func apiClientDidFinishWithResponse(response: Any?) {
switch response {
case is [String: Any]:
print (response) ; //"{\"F\":1, \"B\":12, \"Fi\":11}"
case is [[String: Any]]:
print (response); // "[{\"Fd\":1}, {\"BM\":12}, {\"Fi\":11}]"
case is [Any]:
print (response) // "[\"For\", \"BW\", \"Fit\"]"
default : break;
}
}