What's the best way in the Silverlight API to convert a basic json Symbol string (in this case a SimpleLineSymbol) to an object, without me needing to set the color and width manual."result" is a temporary object that i already created from the original json string.Original JSON string:Note that the SimpleLineSymbol only needs four properties: type, style, color and width. The other properties just need to be discarded; they are the cumulative collection of all the symbols properties.{
"angle":null,
"backgroundColor":null,
"borderLineColor":null,
"color":[156,156,156,255],
"contentType":null,
"font":null,
"height":null,
"horizontalAlignment":null,
"imageData":null,
"kerning":null,
"outline":null,
"rightToLeft":null,
"size":null,
"style":"esriSLSSolid",
"type":"esriSLS",
"url":null,
"verticalAlignment":null,
"width":2,
"xoffset":null,
"xscale":null,
"yoffset":null,
"yscale":null
}
Current code to convert it: SimpleLineSymbol symbol = (SimpleLineSymbol)Json.ConvertToObject(json, typeof(SimpleLineSymbol));
if (result.color != null && result.color.Count == 4)
{
symbol.Color = new SolidColorBrush(Color.FromArgb(
(byte)(result.color[3] & 0xff), (byte)(result.color[0] & 0xff), (byte)(result.color[1] & 0xff), (byte)(result.color[2] & 0xff)));
symbol.Width = result.width;
}
the current Json converter: public static object ConvertToObject(string json, Type type)
{
using (MemoryStream memoryStream = new MemoryStream())
{
byte[] bytes = Encoding.UTF8.GetBytes(json);
memoryStream.Write(bytes, 0, bytes.Length);
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(type);
return dataContractJsonSerializer.ReadObject(memoryStream);
}
}
Thanks for your feedback.