1

我有一个工作代码,可以将订阅者的电子邮件发送到 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();
    //...
  }
}
4

1 回答 1

2

你有没有尝试过:

data.Add("merge_vars", new Dictionary<string, string> { {"FNAME", firstname} });
于 2013-01-16T04:54:50.307 回答