2017-01-16 113 views
0

當我想向感興趣的用戶添加訂閱者時,將布爾值設置爲true,它仍然爲false。使用類似的請求更新合併字段值時,我沒有問題。在調試時,我注意到兩者之間的一個區別,那就是利益在請求一個「關鍵」和「價值」,而合併字段沒有:無法將訂閱者添加到MailChimp API 3.0組中#

enter image description here

響應有關利益樣子這並沒有「鑰匙」和「價值」。

enter image description here

我在做什麼錯誤?

我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} });

+1

'當我想添加一個用戶興趣它不起作用....請解釋'它不工作'的意思。你有錯誤嗎? – ekad

+0

@ekad謝謝你讓我更好地問我的問題。我改述了這個問題,即使我嘗試將其設置爲true,布爾值仍然爲false。 – ptrask

回答

0

出於某種原因,我沒有得到我更新了成員的錯誤,但在工作的時候我試圖創建一個具有上述類的新成員我從API中收到了一個錯誤的請求,即興趣是一個數組,而不是它必須的對象。爲了解決這個問題,我將我的興趣Dictionary<string,bool>改爲Dictionary<string,object>

最初當我改變字典時,我最終得到了兩個幾乎完全相同的構造函數,因此我的錯誤是「調用在下面的方法或屬性之間不明確」。

相關問題