I have created a class that will hold the list of key/values serialized as JSON.
Here is the class:
```
class ArrayOfBase64Array
{
// serialized JSON
private List<string> list = new List<string>();
public void Add(NameValueCollection collection)
{
foreach(var key in collection.AllKeys)
{
this.Add(key, collection[key]);
}
}
public void Add<T>(string key, T value) {
var dict = new Dictionary<string,T>();
dict.Add(key, value);
var json = JsonConvert.SerializeObject(dict);
list.Add(Base64Encode(json));
}
public string[] ToArray()
{
return list.ToArray();
}
string Base64Encode(string value)
{
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
}
}
```
The AddOrder payload expects a shape that matches this C# class:
```
// lots of fields omitted for brevity
class AddOrder
{
public string action {get;set;}
public string[] domain {get;set;}
public string[] customfields {get;set;}
}
```
To create an AddOrder instance with customfields you can now do this:
```
// create an AddOrder instance
var addOrder = new AddOrder
{
action = "AddOrder",
domain = new [] {"one.example.com", "two.example.com"}
};
// build our customfields collection
var cfarray = new ArrayOfBase64Array();
cfarray.Add("1", "FuBar");
cfarray.Add("2", 999);
cfarray.Add("3", true);
cfarray.Add("4", new JObject(new JProperty("Foo", 4711.42)));
// or if you have a namevaluecollection
var nvc = new NameValueCollection { {"5", "test namevalue 1"}, {"6", "another value"} };
cfarray.Add(nvc);
// store the customfields as an array of strings
addOrder.customfields = cfarray.ToArray();
```
This is what the data looks like when POST-ed to the server:
```JSON
{ "action":"AddOrder",
"domain":["one.example.com","two.example.com"],
"customfields":[
"eyIxIjoiRnVCYXIifQ==",
"eyIyIjo5OTl9",
"eyIzIjp0cnVlfQ==",
"eyI0Ijp7IkZvbyI6NDcxMS40Mn19",
"eyI1IjoidGVzdCBuYW1ldmFsdWUgMSJ9",
"eyI2IjoiYW5vdGhlciB2YWx1ZSJ9"]
}
```
And this is what is in each of the encoded base64 strings:
```JSON
{"1":"FuBar"}
{"2":999}
{"3":true}
{"4":{"Foo":4711.42}}
{"5":"test namevalue 1"}
{"6":"another value"}
```