Swift JSON error : Could not cast value of type ‘__NSDictionaryM’ to ‘NSArray’

The bitnami response starts with a { and it is therefore a JSON object, which corresponds to an NSDictionary. The other one starts with [ which indicates an array.

You need to change the type of json to Dictionary<String, AnyObject>, and deserialize as follows:

json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! Dictionary<String, AnyObject>

Leave a Comment