If I want to get data from a local json file, I use this method to report an error:
Cannot invoke 'jsonObject' with an argument list of type '(with: NSData, options: JSONSerialization.ReadingOptions)'
let path = Bundle.main.path(forResource: "baseInfo", ofType: "json")
let data = NSData(contentsOfFile: path!)
let jsonOb = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)
It turned out that there was a problem with the type of a parameter, and I was entangled for a long time.
let jsonOb = try! JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers)
Because the parameter type required here is Data
not NSData
, habitually think it is the same, habitual harm. . .