I have defined a type in C# called
using Message = System.Collections.Generic.Dictionary<string, object>;
I have no problem with sending this from a C# server to the C# client.
But now they want one of the value pairs to be an array of Message, as illustrated (the tracked variable with dummy values) below:
Message msg = new Message();
msg.Add("timestamp", Tools.ToMS(seconds, microseconds));
msg.Add("DateTime", Tools.ToISO(this.seconds, this.microseconds));
msg.Add("guid", Guid.NewGuid().ToString());
msg.Add("heading", this.heading);
msg.Add("correction", this.correction);
msg.Add("valid", this.valid);
msg.Add("lat", lat);
msg.Add("lon", lon);
msg.Add("altitude", altitude);
msg.Add("Channel", "Oxford.GPS");
Message[] tracked = new Message[2];
tracked[0] = new Message();
tracked[1] = new Message();
tracked[0].Add("first", 1);
tracked[1].Add("second", 2);
msg.Add("tracked", tracked);
return msg;
Ok, I get no errors in sending, but on the receiving side the embedded Dictionary is not converting to a Dictionary, instead I am getting an array of Newtonsoft.Json.Linq.JArray
Type: Object
HasValues: 1
First: [1x1 Newtonsoft.Json.Linq.JProperty]
Last: [1x1 Newtonsoft.Json.Linq.JProperty]
Count: 1
Parent: [1x1 Newtonsoft.Json.Linq.JArray]
Root: [1x1 Newtonsoft.Json.Linq.JArray]
Next: [1x1 Newtonsoft.Json.Linq.JObject]
Previous: []
Path: [1x1 System.String]
Here is what the Detailed Trace is showing arriving at the Client, which looks good to my untrained eyes:
{"C":"d-4A172629-B,5549|C,0|D,1","M":[{"H":"GatewayHub","M":"post","A":[{"timestamp":1450469910308,"DateTime":"2015-12-18T20:18:30.3090000Z","guid":"60ef4307-1225-40f9-b0e0-f2f1d87e760d","heading":210.340958,"correction":3,"valid":true,"lat":42.299856271140619,"lon":-83.698864895162188,"altitude":269.147216796875,"Channel":"Oxford.GPS","tracked":[{"first":1},{"second":2}]}]}]})
Yes, believe it or not, I am then sending this via an event to Matlab, which also works, but not for the nested values.