I'm getting JSON from a web service in the following format:

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).

Answered by DTS Engineer in 717702022

Casting to a very complex type like this as not best practice. Rather, do the following:

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"

Accepted Answer

Casting to a very complex type like this as not best practice. Rather, do the following:

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"

I'm getting JSON from a web service in the following format:
 
 
Q