【发布时间】:2011-01-06 04:04:02
【问题描述】:
我有一堂课:
[Serializable]
public class KVPair<TKey, TValue>
{
public TKey Key { get; set; }
public TValue Value { get; set; }
public KVPair(TKey k, TValue v)
{
Key = k;
Value = v;
}
}
我创造的:
List<KVPair<string,string>> kvPairs;
使用 JSON.Net 库我可以序列化列表并产生:
"[{\"Key\":\"Two\",\"Value\":\"2\"},{\"Key\":\"One\",\"Value\":\"1\"}]"
当我将此字符串反序列化回列表时> 我得到了正确的对象计数,但它们为空。任何建议都会有很大帮助。
【问题讨论】:
-
你知道已经有 KeyValuePair
类型了吗? -
检查这个 SO 问题,因为使用 web 服务序列化 KeyValuePair 存在问题:stackoverflow.com/questions/83232/…
标签: c# generics serialization json.net