2010-04-23 86 views
0

我使用MailChimp的API將電子郵件訂閱到列表。功能listsubscribe()用於電子郵件訂閱:Php 2d數組作爲C#2d數組/結構體

public static listSubscribe(string apikey, string id, string email_address, array merge_vars, string email_type, boolean double_optin, boolean update_existing, boolean replace_interests, boolean send_welcome) 

我下載MailChimp官方.NET wrapper他們的API

當在Visual Studio中尋找,這是重載函數之一:

listSubscribe(string apikey, string id, string email_address, MCMergeVar[] merges) 

當我點擊在MCMergeVar []的定義上,這個出來:

[XmlRpcMissingMapping(MappingAction.Ignore)] 
    public struct MCMergeVar 
    { 
     public string name; 
     public bool req; 
     [XmlRpcMissingMapping(MappingAction.Error)] 
     public string tag; 
     public string val; 
    } 

在上MailChimp的網站上的PHP爲例,這是merges變量是如何聲明:

$merge_vars = array('FNAME'=>'Test', 'LNAME'=>'Account', 'INTERESTS'=>''); 

如何正確地寫這個數組我的C#包裝? 我想是這樣的:

MCMergeVar[] subMergeVars = new MCMergeVar[1]; 
subMergeVars["FNAME"] = "Test User"; 

但是,它需要在一個地方,其中int"FNAME"現在擺,所以這不工作...提前

感謝, 島

編輯1: 我試過FoxFire的解決方案,但沒有數據從subMergeVars傳遞給MailChimp服務器,只有電子郵件通過:

// Subscribe email to list 
      string subID = "26973e52cc"; 
      string subEmail = "[email protected]"; 
      MCMergeVar[] subMergeVars = new MCMergeVar[5]; 
      subMergeVars[0].name = "FNAME"; 
      subMergeVars[0].val = "FNDynamic"; 
      subMergeVars[1].name = "LNAME"; 
      subMergeVars[1].val = "LNDynamic"; 

      mailChimp.api.listSubscribe(subID, subEmail, subMergeVars, "html"); 

回答

1

最有可能的:

MCMergeVar[] subMergeVars = new MCMergeVar[1]; 
subMergeVars[0].name = "FNAME"; 
subMergeVars[0].val = "Test User"; 
+0

它看起來不錯給我,但數據仍不會傳遞到MailChimp服務器.. 。現在我將編輯我的問題,用我試過的例子 – 2010-04-23 13:04:00

+0

我想到了...... .name需要用.val替換,它工作得很好:) 謝謝! – 2010-04-23 13:22:40

+0

它不清楚你的意思是「.name需要用.val替換」。 你能發佈一個片段嗎? – 2010-05-06 09:55:08

0

嘗試:

var mergeVars = new List<MCMergeVar>(); 

mergeVars.Add(new MCMergeVar() { tag = "FNAME", val = "Test User First Name" }); 
mergeVars.Add(new MCMergeVar() { tag = "LNAME", val = "Test User Last Name" }); 

然後使用:

mergeVars.ToArray()