How To Create Data Json Object from Empty String

This is what I tried to do. I am not sure what is wrong. anyone got ideas?

let data: Data? = try? JSONSerialization.data(withJSONObject: "")

and it says

reason: '*** +[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write'

even if i put in "{}" error is the same. thoughts?

Purpose for this is i want set this to a URLRequest.httpBody

Thoughts?

Answered by Claude31 in 741825022

Why don't you just pass empty data:

request.httpBody = Data()
Accepted Answer

Why don't you just pass empty data:

request.httpBody = Data()
How To Create Data Json Object from Empty String
 
 
Q