using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
Dic = new Dictionary<string, string>
string json = JsonConvert.SerializeObject(model, Formatting.Indented);
public int ID { get; set; }
[JsonConverter(typeof(CustomDictionaryConverter))]
public Dictionary<string, string> Dic { get; set; }
public class CustomDictionaryConverter : JsonConverter
public override bool CanConvert(Type objectType)
return typeof(IDictionary).IsAssignableFrom(objectType);
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
IDictionary dict = (IDictionary)value;
JArray array = new JArray();
foreach (DictionaryEntry kvp in dict)
JObject obj = new JObject();
obj.Add(kvp.Key.ToString(), kvp.Value != null ? JToken.FromObject(kvp.Value, serializer) : new JValue((string)null));
public override bool CanRead
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
throw new NotImplementedException();