我正在尝试创建一个 JSON 请求以发送到电子邮件服务 GetResponse 以将联系人添加到邮件活动。
我想要实现的格式是add_contact
[
"API_KEY",
{
"campaign" : "CAMPAIGN_ID",
"action" : "action_value",
"name" : "name_value",
"email" : "email_value",
"cycle_day" : cycle_day_value,
"ip" : "ip_value",
"customs" : [
{
"name" : "name_1_value",
"content" : "content_1_value"
},
{
"name" : "name_2_value",
"content" : "content_2_value"
}
]
}
]
在如何在 C# 中创建 JSON 字符串之后,我构建了这个设置
private class AddContactRequest
{
public string campaign { get; set; }
public string action { get; set; }
public string name { get; set; }
public string email { get; set; }
public int cycle_day { get; set; }
public string ip { get; set; }
}
像这样填满
AddContactRequest add = new AddContactRequest();
add.campaign = campaignID;
add.action = action
add.name = contact_name;
add.email = email;
add.cycle_day = cycle_day;
add.ip = ip_value;
string json = new JavaScriptSerializer().Serialize(add);
这里json符合预期
{"campaign":"my_test_campaign","action":"standard","name":"Test Name","email":"test@example.com","cycle_day":0,"ip":"10.1.0.5"}
我不知道如何正确地将API_KEY
字符串添加到它的前面。
如何更改它以将其添加API_KEY
到它的前面而不附加属性名称,理想情况下使用JavaScriptSerializer()
?