Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c语言中的多级字典错误#_C#_Json_Dictionary_Keynotfoundexception - Fatal编程技术网

C# c语言中的多级字典错误#

C# c语言中的多级字典错误#,c#,json,dictionary,keynotfoundexception,C#,Json,Dictionary,Keynotfoundexception,我使用下面的代码生成JSON FilterModel f = new FilterModel(); f.FilterName = "EducationLevel"; f.filterValue = new List<string>(); f.filterValue.Add("BE"); f.GroupName="Education"; FilterDictionary d = new

我使用下面的代码生成JSON

        FilterModel f = new FilterModel();
        f.FilterName = "EducationLevel";
        f.filterValue = new List<string>();
        f.filterValue.Add("BE");
        f.GroupName="Education";


        FilterDictionary d = new FilterDictionary();
        d.FilterValuse = new Dictionary<string, List<string>>();
        d.FilterValuse.Add(f.FilterName, f.filterValue);

        FilterSelectModel ff = new FilterSelectModel();

        ff.Filters = new Dictionary<string, Dictionary<string, List<string>>>();

        ff.Filters[f.GroupName].Add(f.FilterName, f.filterValue);



        var json = new JavaScriptSerializer().Serialize(ff);
        Response.Write(json);
它显示以下错误

字典中不存在给定的键

出了什么问题?任何人都可以帮助我更改此代码:

ff.Filters[f.GroupName].Add(f.FilterName, f.filterValue);
致:

ff.Filters.Add(f.GroupName,newdictionary())
{{f.FilterName,f.filterValue}});
希望这能解决你的问题


检查此

ff。筛选器[教育]
不存在。您只需初始化并尝试获取一个key@Dev.ArunCC那么,我如何才能使更改生效呢?请尝试回答,并让我知道您的问题的状态
ff.Filters[f.GroupName].Add(f.FilterName, f.filterValue);
ff.Filters.Add(f.GroupName, new Dictionary<string, List<string>>() 
 { {f.FilterName, f.filterValue} });