I am a beginner in C # and ASP.NET, and I have doubts about JSON and dictionaries
I have a serialized dictionary that has been stored in the database with:
var json = new System.Web.Script.Serialization.JavaScriptSerializer()
.Serialize(filtros.ToDictionary(item => item.Key.ToString(),
item => item.Value.ToString()));
After serializing this dictionary it is stored in the database, because this information I will use later in a view (PopUp in asp.net).
My difficulty is to deserialize these values that are in the database to put them back into a dictionary. I tried:
Code that you used to retrieve the information in the database:
<asp:Literal ID="lblFiltros" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "FiltroJson")%> ' />
The only way you could collect the information in the code behind was:
object filtros = new System.Web.Script.Serialization.JavaScriptSerializer()
.DeserializeObject(((Literal)e.Item.FindControl("lblFiltros")).Text);
However, I can not use it with iterations and it's not even a Dictionary. With Dictionary I used the following code snippet:
System.Collections.Generic.Dictionary<string, string> filtros = new
System.Collections.Generic.Dictionary<string, string>();
That is, when I need .Add
to chave
and valor
in my Dictionary I not only have a large string which is the value I get in Literal
:
((Literal)e.Item.FindControl("lblFiltros")).Text
How can I do this conversion in the right way? Thank you.