decode Json string to class object Swift

前端 未结 2 352
有刺的猬
有刺的猬 2021-01-18 17:09
 private func createWeatherObjectWith(json: Data, x:Any.Type ,completion: @escaping (_ data: Any?, _ error: Error?) -> Void) {
        do {
            let decode         


        
2条回答
  •  一生所求
    2021-01-18 17:55

    Trying to decode any type of Object to String in Swift 4.1

    func convertAnyObjectToJSONString(from object:Any) -> String? {
    
        guard let data = try? JSONSerialization.data(withJSONObject: object, options: []) else { 
    
            return nil 
        }
    
        return String(data: data, encoding: String.Encoding.utf8) 
    }
    

提交回复
热议问题