简体   繁体   English

PHP 2D数组作为C#2D数组/结构

[英]Php 2d array as C# 2d array/struct

I'm using MailChimp's API to subscribe email to a list. 我正在使用MailChimp的API将电子邮件订阅到列表。 Function listsubscribe() is used for email subscription: 函数listsubscribe()用于电子邮件订阅:

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 我为其API下载了MailChimp的官方.NET包装器

When looking in Visual Studio, this is one of overloaded functions: 在Visual Studio中查看时,这是重载函数之一:

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

When I click on definition of MCMergeVar[], this comes out: 当我单击MCMergeVar []的定义时,结果如下:

[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: 在MailChimp网站上的php示例中,这是声明merges变量的方式:

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

How to write this array correctly for my C# wrapper? 如何为我的C#包装器正确编写此数组? 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... 但是它需要在现在放置"FNAME"地方放置一个int ,因此这是行不通的...

Thanks in advance, Ile 在此先感谢Ile

EDIT 1: I tried FoxFire's solution but no data from subMergeVars is passed to MailChimp server, only email is passed: 编辑1:我尝试了FoxFire的解决方案,但没有将subMergeVars的数据传递到MailChimp服务器,仅传递了电子邮件:

// 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");

Most likely: 最有可能的:

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

Try: 尝试:

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

Then use: 然后使用:

mergeVars.ToArray()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM