我正在使用此代码从 url 获取 json 数据:
URLSession.shared.dataTask(with:request, completionHandler: { (data, response, error) in
guard let data = data, error == nil else { return }
do {
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String:String]
completion(json)
} catch _ as NSError {
completion(nil)
}
}).resume()
如果我的 json 是{"error":"true","message":"no"}
它工作正常
但是,如果我将 json 用于 json,它就不起作用:
{"error":"true","message":"no","state":{"id":"1","name":"empty"}}