http://stackoverflow.com/questions/34047955/serializing-deserializing-arrays-with-mixed-types-using-json-net

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
					
public class Program
{
	public static void Main()
	{
        string json = @"
        { 
            ""stops"": 
            [
                [0.1, ""#55BF3B""],
                [0.5, ""#DDDF0D""],
                [0.9, ""#DF5353""]
            ]
        }";

        RootObject obj = JsonConvert.DeserializeObject<RootObject>(json);
        foreach (Stop stop in obj.Stops)
        {
            Console.WriteLine("Value: " + stop.Value);
            Console.WriteLine("Color: " + stop.Color);
            Console.WriteLine();
        }

        json = JsonConvert.SerializeObject(obj, Formatting.Indented);
        Console.WriteLine(json);
	}
}

class RootObject
{
    [JsonProperty("stops")]
    public List<Stop> Stops { get; set; }
}

[JsonConverter(typeof(StopConverter))]
public class Stop
{
    public decimal Value { get; set; }
    public string Color { get; set; }
}

class StopConverter : JsonConverter
{
    public override bool CanConvert(Type objectType)
    {
        return (objectType == typeof(Stop));
    }

    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        JArray ja = JArray.Load(reader);
        Stop stop = new Stop();
        stop.Value = (decimal)ja[0];
        stop.Color = (string)ja[1];
        return stop;
    }

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        JArray ja = new JArray();
        Stop stop = (Stop)value;
        ja.Add(stop.Value);
        ja.Add(stop.Color);
        ja.WriteTo(writer);
    }
}
;