decode Json string to class object Swift
问题 private func createWeatherObjectWith(json: Data, x:Any.Type ,completion: @escaping (_ data: Any?, _ error: Error?) -> Void) { do { let decoder = JSONDecoder() decoder.keyDecodingStrategy = .convertFromSnakeCase let weather = try decoder.decode(x.self, from: json) return completion(weather, nil) } catch let error { print("Error creating current weather from JSON because: \(error.localizedDescription)") return completion(nil, error) } } Here I write above code to decode Json string to class