我有以下代码,使用Swift将联系人添加到Sendgrid联系人列表中
var request = URLRequest(url: URL(string: sendGridURL)!)
request.httpMethod = "PUT"
//Headers
request.addValue("Bearer \(sendGridAPIKey)", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
//Data
let json = {
"list_ids": listIds,
"contacts": [{
"email": email
}]};
do {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
request.httpBody = data
} catch {
print("\(error)")
}
URLSession.shared.dataTask(with: request) { (data, response, error) in
guard error == nil else { print(error!.localizedDescription); return }
guard let data = data else { print("Empty data"); return }
if let str = String(data: data, encoding: .utf8) {
print(str)
}
let params = [
"UserId": MUser.sharedInstance.userId,
"SendMethod": "Sendgrid"
];
// Flurry.logEvent("WelcomeEmailSend", withParameters: params);
//
}.resume()
此处失败:
let json = {
"list_ids": listIds,
"contacts": [{
"email": email
}]};
有错误 行上的连续语句必须用';'
分隔