我在 .NET 中使用 ServiceStack.Text。我想序列化一个实例:
IDictionary<string, ResourceSpec>
资源规范是:
public class ResourceSpec
{
public string TypeName
{
get;
set;
}
public HashSet<Property> Properties
{
get;
set;
}
}
它序列化成这种格式:
{1:{"TypeName":"channel","Properties":[audio,video]},2:{"TypeName":"channel","Properties":[audio,video,encrypted]}}
当我尝试反序列化它时:
JsonSerializer.DeserializeFromStream<IDictionary<string, ResourceSpec>>(file);
我得到例外:
SerializationException: "Type definitions should start with a '{', expecting serialized type 'ResourceSpec', got string starting with: Properties"
有什么想法有什么问题吗?