duanli8391 2010-04-23 12:17
浏览 76
已采纳

Php 2d数组为C#2d数组/结构

I'm using MailChimp's API to subscribe email to a list. Function listsubscribe() is used for email subscription:

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)

I downloaded MailChimp's official .NET wrapper for their API

When looking in Visual Studio, this is one of overloaded functions:

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

When I click on definition of MCMergeVar[], this comes out:

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

In a php example on MailChimp's website, this is how merges variable is declared:

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

How to write this array correctly for my C# wrapper? I tried something like this:

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

But it requires an int in place where "FNAME" is now placed, so this doesn't work...

Thanks in advance, Ile

EDIT 1: I tried FoxFire's solution but no data from subMergeVars is passed to MailChimp server, only email is passed:

// Subscribe email to list
            string subID = "26973e52cc";
            string subEmail = "mymail@some.com.hr";
            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");
  • 写回答

2条回答 默认 最新

  • doudiecai1572 2010-04-23 12:39
    关注

    Most likely:

    MCMergeVar[] subMergeVars = new MCMergeVar[1]; 
    subMergeVars[0].name = "FNAME"; 
    subMergeVars[0].val = "Test User"; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码