當我想向感興趣的用戶添加訂閱者時,將布爾值設置爲true,它仍然爲false。使用類似的請求更新合併字段值時,我沒有問題。在調試時,我注意到兩者之間的一個區別,那就是利益在請求一個「關鍵」和「價值」,而合併字段沒有:無法將訂閱者添加到MailChimp API 3.0組中#
響應有關利益樣子這並沒有「鑰匙」和「價值」。
我在做什麼錯誤?
我updateMember功能的相關部分看起來是這樣的:
static void updateMember(){
Dictionary<string, object> mergefieldsDic = new Dictionary<string, object>();
mergefieldsDic.Add("POSTCODE","4242");
Dictionary<string, bool> interestDic = new Dictionary<object, bool>();
interestDic.Add("cb0b422bf8", true);
request.RequestFormat = DataFormat.Json;
request.AddBody(new MemberRequest(mergefieldsDic, interestDic));
IRestResponse<Member> response = client.Execute<Member>(request);
foreach (var key in response.Data.merge_fields.Keys)
{
string value = response.Data.merge_fields[key].ToString();
Console.WriteLine(value);
}
foreach (var key in response.Data.interests.Keys)
{
string value = response.Data.interests[key].ToString();
Console.WriteLine(value);
}
}
我MemberRequest類看起來像這樣
public class MemberRequest
{
public MemberRequest(){}
public MemberRequest(Dictionary<string, object> merge_fields, Dictionary<object, bool> interests)
{
this.merge_fields = merge_fields;
this.interests = interests;
}
public string email_address { get; set; }
public string status { get; set; }
public Dictionary<string,object> merge_fields { get; set; }
public Dictionary<object, bool> interests { get; set; }
}
我的會員類看起來像這樣
public class Member
{
public string id { get; set; }
public string email_address { get; set; }
public string status { get; set; }
public Dictionary<string,object> merge_fields { get; set; }
public Dictionary<object,bool> interests { get; set; }
}
我試圖將這兩種興趣詞典更改爲<bool,object>
,\<string,bool>
和<string,string>
,但沒有任何工作。
我設法得到它,如果我不使用MemberRequest類,只是做request.AddBody(new { interests = new { cb0b422bf8 = true} });
'當我想添加一個用戶興趣它不起作用....請解釋'它不工作'的意思。你有錯誤嗎? – ekad
@ekad謝謝你讓我更好地問我的問題。我改述了這個問題,即使我嘗試將其設置爲true,布爾值仍然爲false。 – ptrask