Type 'Any' has no subscript members error

how can I fix Type 'Any' has no subscript members error

this is my code

Well, when you cast someArray to an NSArray it doesn't know what the elements inside this array are. So the items are of type Any. You can check if the item itself is a dictionary and then if this dictionary contains a String for the key "fname".

If the structure of your JSON is always the same, you will be a lot happier using Swift's Codable instead of JSONSerialization.

Take a look here: https://developer.apple.com/documentation/foundation/archives_and_serialization/using_json_with_custom_types

thank dear but I didn't understand how can I write with Codable :disappointed: can you write my code with Codable?

You will need to know the structure of the JSON that is being returned from the server and create a struct or class that matches this structure.

I strongly suggest you look at the link I shared and download the sample code there. The playground shows you in real code how Codable works.

Terms of Service

Privacy Policy

Cookie Policy