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

时间:2019-10-13 03:16:17

标签: ios swift

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

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

1 个答案:

答案 0 :(得分:1)

问题出在字典email: email上,其中{}不是公认的关键字。您可以这样定义json:

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

或者如果您希望在与代码的联系中构造字典,则可以执行以下操作:

let json = [

    "listIds": [""],
    "contacts": [[ "email" : "\(email)" ]]
];