Swift*Cannot invoke 'jsonObject' with an argument list of type

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 Datanot NSData, habitually think it is the same, habitual harm. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325892322&siteId=291194637