Problems with Json Serialize Dictionary

后端 未结 5 2386
自闭症患者
自闭症患者 2021-02-19 16:55

whenever i try to serialize the dictionary i get the exception:

System.ArgumentException: Type 
\'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializ         


        
5条回答
  •  迷失自我
    2021-02-19 17:35

    I’ve created JavaScriptSerializer extension DeserializeDictionary- see http://geekswithblogs.net/mnf/archive/2011/06/03/javascriptserializer-extension-deserializedictionarytkey-tvalue.aspx

    public static Dictionary  DeserializeDictionary(this JavaScriptSerializer jss, string jsonText)
    {
        var dictWithStringKey = jss.Deserialize>(jsonText);
        var dict=dictWithStringKey.ToDictionary(de => jss.ConvertToType(de.Key),de => de.Value);
            return dict;
    }
    

提交回复
热议问题