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

后端 未结 3 459
自闭症患者
自闭症患者 2020-12-03 18:45

when decoding JSON from webservice(API) i get error :

Could not cast value of type \'__NSDictionaryM\' (0x1037ad8a8) to \'NSArray\' (0x1037ad470). 
         


        
3条回答
  •  囚心锁ツ
    2020-12-03 19:15

    try cache for Serialization

            do {
                if let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String : Any] { // as? data type
                    if let otherDict = json["dataKey"] as? [String : Any] {
                        //do something
                    }
                }
            } catch {
                // can't json serialization
            }
    

提交回复
热议问题