https://imdb-api.com/en/API/BoxOffice/k_92uqzcls
i cast data like this : let output = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! Dictionary<String,Array<Dictionary<String, Any>>>//Array
error: Could not cast value of type '__NSCFConstantString' (0x7fff869ca888) to 'NSArray' (0x7fff869ca8e8).
Casting to a very complex type like this as not best practice. Rather, do the following:
-
Continue using
JSONSerializationand cast one level at a time. -
Switch to using
JSONDecoder. See Encoding and Decoding Custom Types.
The second option is best if the JSON uses a regular format, and that certainly looks like the case here. I generally only use the first option if the JSON is highly irregular, and thus I need to check stuff as I decode it.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"