1

我在 .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"

有什么想法有什么问题吗?

4

1 回答 1

1

您的序列化字符串似乎缺少一些双引号,例如“1”和“audio”、“video”等。使用 3.9.71 对我来说,引用的字符串反序列化很好。

于 2014-10-16T13:10:14.843 回答