Use this generic class in order to serialize / deserialize JSON.
You can easy serialize complex data structure like this:
Dictionary<string, Tuple<int, int[], bool, string>>
to JSON string and then to save it in application setting or else
public class JsonSerializer
{
public string Serialize<T>(T Obj)
{
using (var ms = new MemoryStream())
{
DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(T));
serialiser.WriteObject(ms, Obj);
byte[] json = ms.ToArray();
return Encoding.UTF8.GetString(json, 0, json.Length);
}
}
public T Deserialize<T>(string Json)
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Json)))
{
DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(T));
var deserializedObj = (T)serialiser.ReadObject(ms);
return deserializedObj;
}
}
}