json - Multi level dictionary error in c# -


im using following code make 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); 

but shows exception in bellow line

ff.filters[f.groupname].add(f.filtername, f.filtervalue); 

it shows following error

the given key not present in dictionary

what went wrong ? 1 can me

change code:

ff.filters[f.groupname].add(f.filtername, f.filtervalue); 

to:

ff.filters.add(f.groupname, new dictionary<string, list<string>>()   { {f.filtername, f.filtervalue} }); 

hope resolve issue.

check out how to: initialize dictionary collection initializer (c# programming guide)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -