【发布时间】:2014-08-21 13:48:48
【问题描述】:
我已经使用 JavaScriptSerializer 在 JSON 中序列化 System.Drawing.Color,但是当我尝试对其进行反序列化时,它返回所有值为 0 的 Color 对象。
示例 JSON 如下。
{
"A":255,
"B":0,
"G":165,
"IsEmpty":false,
"IsKnownColor":true,
"IsNamedColor":true,
"IsSystemColor":false,
"Name":"Orange",
"R":255
}
这是反序列化对象的屏幕截图。
然后我尝试使用 JSON.net(newtonsoft.json) 库。它给了我以下错误。
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Drawing.Color' because the type requires a JSON string value to deserialize correctly.
有没有办法将 JSON 反序列化为对象着色。我发现 this 类似的问题没有任何答案。
【问题讨论】:
标签: c# json serialization deserialization json-deserialization