using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; namespace Plugins.Countly.Helpers { class CustomJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(Dictionary>>); } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var customValue = value as Dictionary>>; if (customValue == null || customValue.Count == 0) return; var list = customValue.First().Value as List>; if (list == null || list.Count == 0) return; writer.WriteStartObject(); foreach (var item in list) { writer.WritePropertyName(item.Key); serializer.Serialize(writer, item.Value); } writer.WriteEndObject(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { throw new NotImplementedException(); } } }