1

.NET で ServiceStack.Text を使用しています。次のインスタンスをシリアル化したい:

IDictionary<string, ResourceSpec>

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 に答える