I have made a request to my server in my app. And posted data something like this.Server side is waiting for all parameters even they are nil. But i couldn\'t add nil values to
As documented in here, setting nil
for a key in dictionary means removing the element itself.
If you want null
when converting to JSON
for example, you can use NSNull()
var postDict = Dictionary()
postDict["pass"]=123
postDict["name"]="ali"
postDict["surname"]=NSNull()
let jsonData = NSJSONSerialization.dataWithJSONObject(postDict, options: NSJSONWritingOptions.allZeros, error: nil)!
let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding)!
// -> {"pass":123,"surname":null,"name":"ali"}