Swift 错误:一行上的连续语句必须用 ';' 分隔


let email = MUser.sharedInstance.getUserEmail()
let json = [
"listIds": [""],
"contacts": [{ "email" : "(email)" }]
];

我在运行上面的代码时收到错误Consecutive statements on a line must be separated by ';'。我做错了什么?

问题是字典email: email其中{}不是可识别的关键字 你可以这样定义你的 json:

let json = [
"""
"listIds": [""],
"contacts": [ {"email" : "(email)" }]
"""
];

或者,如果您希望使用代码在联系人中构建字典,则可以执行以下操作:

let json = [
"listIds": [""],
"contacts": [[ "email" : "(email)" ]]
];