I get a whole bunch of "settings" from an API via JSON which looks like this:
{
...
"SettingA": { "value": [
[ 3200, 0 ],
[ 4300, 0 ],
[ 5600, 0 ],
[ 7000, 0 ]
], "type": "array", "readonly": 1},
"SettingB": { "value": [
[ 3, 3320, -0.6, "Auto WB" ],
[ 7, 3200, 0, "Tungsten" ],
[ 7, 4300, 0, "Fluorescent" ],
[ 7, 5600, 0, "Daylight" ],
[ 7, 7000, 0, "Daylight cool" ]
], "type": "array", "readonly": 1}
...
}
Based on the keyword like "SettingA" or "SettingB", I need to serialize it's VALUE property to a specific type (if known, some settings can stay as JTOKEN or JARRAY, as I don't care)
Is there an elgant way of deserializing the VALUE to a corresponding type? Especially, because the properties are NOT NAMED, so I would have to assign properties by index.
Currently, I am doing this (which works, but requires lots of hand-writing):
foreach (JToken item in table)
{
var p = new WhiteBalancePreset(item.Value<int>(0), item.Value<double>(1),
item.Value<double>(2), item.Value<string>(3));
if (p.State != 0)
presets.Add(p);
}