我有一个工作代码,可以将订阅者的电子邮件发送到 C# 中的 MailChimp。
我只需要将 FirstName 添加到其中。从文档来看,merge_vars
似乎是一个多维 JSON 数组。你如何在 C# 中做到这一点?
这是代码
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
Dictionary<string,string> data = new Dictionary<string,string>();
data.Add("apikey", ApiKey);
data.Add("id", ListId);
data.Add("email_address", email);
//data.Add("merge_vars[FNAME]", firstname); // <-- This is what I tried adding but doesn't work
string json = new JavaScriptSerializer().Serialize(data);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
//...
}
}