作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 Dictionary<String, AnyObject>
类型的字典我需要将参数作为 nil 传递:
let params = [
"number": nil,
"description": nil,
"lang" : "spa",
"byFee": true,
"plan" : data.Plan
] as Dictionary<String, AnyObject>
request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(params, options: [])
如果我这样做,我会得到一个错误:
所以我尝试将词典更改为 Dictionary<String, AnyObject?>
但是如果我这样做,那么错误就会出现在请求中。HTTPBody:
最佳答案
JSON 中的空值等同于 ObjC/Swift 中的 NSNull
:
let params : [String : AnyObject] = [
"number": NSNull(),
"description": NSNull(),
"lang" : "spa",
"byFee": true,
"plan" : data.Plan,
]
关于swift - 如何将 nil 作为 dictionary<String,AnyObject> 的参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38314095/
我是一名优秀的程序员,十分优秀!