using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public static void Test()
private static void Test3d()
var root = new double[,,] { { { 1 } } };
private static void Test2d()
var root = new double[,] { { 1 } };
private static void Test1d()
var root = new double[] { 1 };
static void TestArray<T>(System.Array root)
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Arrays };
var json = JsonConvert.SerializeObject(root, Formatting.Indented, settings);
Console.WriteLine("\nTesting an array of type {0}:", root.GetType());
var root2 = JsonConvert.DeserializeAnonymousType(json, root, settings);
root.Rank == root2.Rank &&
Enumerable.Range(0, root.Rank).All(dimension => root.GetLength(dimension) == root2.GetLength(dimension)) &&
root.Cast<T>().SequenceEqual(root2.Cast<T>())
Console.WriteLine("Array round-tripped successfully.");
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);
Console.WriteLine("Json.NET version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");