0

I am unable to implement the JSON using DELETE method to get data from server. Is this the right way to implement delete method, if not can anyone help me?

Here is my code

func deleteWishListItemsDownloadJsonWithURl(deleteApi: String){
        let url = URL(string: deleteApi)
        var request = URLRequest(url: url! as URL)
        request.httpMethod = "DELETE"

        let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
            if error != nil { print(error!); return }
            do {
                if let jsonObj = try JSONSerialization.jsonObject(with: data!) as? String {
                    print(jsonObj)
                    DispatchQueue.main.async {
                       self.tableDetails.reloadData()
                    }
                }
            } catch {
                print(error)
            }
        }
        task.resume()
    }
user0246
  • 65
  • 10

1 Answers1

0

Just replace the

 let jsonObj = try JSONSerialization.jsonObject(with: data!) as! String

with

let jsonObj = try JSONSerialization.jsonObject(with: data!) as! [String:Any]

Also you can take reference from Correctly Parsing JSON in Swift 3

swetansh kumar
  • 475
  • 7
  • 17