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()
Test(@"[[""tBTCUSD"",5694.5,90.04753567,5694.6,90.83915407,-155.4,-0.0266,5694.6,68727.10536905,6007.8,5537]]");
Test("[\"error\",20060,\"maintenance\"]");
static void Test(string json)
Console.WriteLine("Testing JSON: {0}", json);
var reader = new JsonTextReader(new StringReader(json));
var array = JArray.Load(reader);
if (array.Count > 0 && array[0].Type == JTokenType.String && (string)array[0] == "error")
Console.WriteLine("Error response detected.");
else if (array.Count > 0 && array[0].Type == JTokenType.Array)
Console.WriteLine("Normal response detected, array value: ");
var arrayValue = (JArray)array[0];
Console.WriteLine(arrayValue);
throw new JsonException("Unexpected response");
if (array.Count > 0 && array[0].ToString(Formatting.None) == "\"error\"")
Console.WriteLine("Error response detected using ToString(Formatting.None).");
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: ");
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");