public void YahooFinance()
    {
      string input = @"{
""matches"" : [
{""t"":""C"", ""n"":""Citigroup Inc."", ""e"":""NYSE"", ""id"":""662713""}
,{""t"":""CHL"", ""n"":""China Mobile Ltd. (ADR)"", ""e"":""NYSE"", ""id"":""660998""}
,{""t"":""PTR"", ""n"":""PetroChina Company Limited (ADR)"", ""e"":""NYSE"", ""id"":""664536""}
,{""t"":""RIO"", ""n"":""Companhia Vale do Rio Doce (ADR)"", ""e"":""NYSE"", ""id"":""671472""}
,{""t"":""RIOPR"", ""n"":""Companhia Vale do Rio Doce (ADR)"", ""e"":""NYSE"", ""id"":""3512643""}
,{""t"":""CSCO"", ""n"":""Cisco Systems, Inc."", ""e"":""NASDAQ"", ""id"":""99624""}
,{""t"":""CVX"", ""n"":""Chevron Corporation"", ""e"":""NYSE"", ""id"":""667226""}
,{""t"":""TM"", ""n"":""Toyota Motor Corporation (ADR)"", ""e"":""NYSE"", ""id"":""655880""}
,{""t"":""JPM"", ""n"":""JPMorgan Chase \\x26 Co."", ""e"":""NYSE"", ""id"":""665639""}
,{""t"":""COP"", ""n"":""ConocoPhillips"", ""e"":""NYSE"", ""id"":""1691168""}
,{""t"":""LFC"", ""n"":""China Life Insurance Company Ltd. (ADR)"", ""e"":""NYSE"", ""id"":""688679""}
,{""t"":""NOK"", ""n"":""Nokia Corporation (ADR)"", ""e"":""NYSE"", ""id"":""657729""}
,{""t"":""KO"", ""n"":""The Coca-Cola Company"", ""e"":""NYSE"", ""id"":""6550""}
,{""t"":""VZ"", ""n"":""Verizon Communications Inc."", ""e"":""NYSE"", ""id"":""664887""}
,{""t"":""AMX"", ""n"":""America Movil S.A.B de C.V. (ADR)"", ""e"":""NYSE"", ""id"":""665834""}],
""all"" : false
}
";

      using (JsonReader jsonReader = new JsonTextReader(new StringReader(input)))
      {
        while (jsonReader.Read())
        {
          Console.WriteLine(jsonReader.Value);
        }
      }
    }
    private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
    {
      JsonTextReader reader;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XmlNodeConverter converter = new XmlNodeConverter();
      if (deserializeRootElementName != null)
        converter.DeserializeRootElementName = deserializeRootElementName;

      XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());

#if !NET20
     string xmlText = node.OuterXml;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());

      string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
      if (d.Declaration != null)
        linqXmlText = d.Declaration + linqXmlText;

      Assert.AreEqual(xmlText, linqXmlText);
#endif

      return node;
    }
    public void AppendCharsWhileReadingNull()
    {
      string json = @"[
  {
    ""$id"": ""1"",
    ""Name"": ""e1"",
    ""Manager"": null
  },
  {
    ""$id"": ""2"",
    ""Name"": ""e2"",
    ""Manager"": null
  },
  {
    ""$ref"": ""1""
  },
  {
    ""$ref"": ""2""
  }
]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      reader.SetCharBuffer(new char[129]);

      for (int i = 0; i < 15; i++)
      {
        reader.Read();
      }

      reader.Read();
      Assert.AreEqual(JsonToken.Null, reader.TokenType);
    }
    public void ParseAdditionalContent_WhitespaceThenText()
    {
      string json = @"'hi' a";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      while (reader.Read())
      {
      }
    }
    public void ReadNewLines()
    {
      string newLinesText = StringUtils.CarriageReturn + StringUtils.CarriageReturnLineFeed + StringUtils.LineFeed + StringUtils.CarriageReturnLineFeed + " " + StringUtils.CarriageReturn + StringUtils.CarriageReturnLineFeed;

      string json =
        newLinesText
        + "{" + newLinesText
        + "'" + newLinesText
        + "name1" + newLinesText
        + "'" + newLinesText
        + ":" + newLinesText
        + "[" + newLinesText
        + "new" + newLinesText
        + "Date" + newLinesText
        + "(" + newLinesText
        + "1" + newLinesText
        + "," + newLinesText
        + "null" + newLinesText
        + "/*" + newLinesText
        + "blah comment" + newLinesText
        + "*/" + newLinesText
        + ")" + newLinesText
        + "," + newLinesText
        + "1.1111" + newLinesText
        + "]" + newLinesText
        + "," + newLinesText
        + "name2" + newLinesText
        + ":" + newLinesText
        + "{" + newLinesText
        + "}" + newLinesText
        + "}" + newLinesText;

      int count = 0;
      StringReader sr = new StringReader(newLinesText);
      while (sr.ReadLine() != null)
      {
        count++;
      }

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(7, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(31, reader.LineNumber);
      Assert.AreEqual(newLinesText + "name1" + newLinesText, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(37, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(55, reader.LineNumber);
      Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
      Assert.AreEqual("Date", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(61, reader.LineNumber);
      Assert.AreEqual(1, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(73, reader.LineNumber);
      Assert.AreEqual(null, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(91, reader.LineNumber);
      Assert.AreEqual(newLinesText + "blah comment" + newLinesText, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(97, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(109, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(115, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(133, reader.LineNumber);
      Assert.AreEqual("name2", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(139, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(145, reader.LineNumber);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(151, reader.LineNumber);
    }
    public void ReadFloatingPointNumber()
    {
      string json =
        @"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]";

      using (JsonReader jsonReader = new JsonTextReader(new StringReader(json)))
      {
        jsonReader.Read();
        Assert.AreEqual(JsonToken.StartArray, jsonReader.TokenType);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(0.0, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(0.0, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(0.1, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(1.0, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(1.000001, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(1E-06, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(4.94065645841247E-324, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.PositiveInfinity, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.NegativeInfinity, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.NaN, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.MaxValue, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.MinValue, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.PositiveInfinity, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.NegativeInfinity, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
        Assert.AreEqual(double.NaN, jsonReader.Value);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
      }
    }
 static void JsonBodyToSoapXml(Stream json, Stream xml)
 {
   Newtonsoft.Json4.JsonSerializerSettings settings = new Newtonsoft.Json4.JsonSerializerSettings();
   settings.Converters.Add(new Newtonsoft.Json4.Converters.XmlNodeConverter());
   Newtonsoft.Json4.JsonSerializer serializer = Newtonsoft.Json4.JsonSerializer.Create(settings);
   using (Newtonsoft.Json4.JsonTextReader reader = new Newtonsoft.Json4.JsonTextReader(new System.IO.StreamReader(json)))
   {
     XmlDocument doc = (XmlDocument)serializer.Deserialize(reader, typeof(XmlDocument));
     if (reader.Read() && reader.TokenType != JsonToken.Comment)
       throw new JsonSerializationException("Additional text found in JSON string after finishing deserializing object.");
     using (XmlWriter writer = XmlWriter.Create(xml))
     {
       doc.Save(writer);
     }
   }
 }
    public void FloatingPointNonFiniteNumbers()
    {
      string input = @"[
  NaN,
  Infinity,
  -Infinity
]";

      StringReader sr = new StringReader(input);

      using (JsonReader jsonReader = new JsonTextReader(sr))
      {
        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
        Assert.AreEqual(jsonReader.Value, double.NaN);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
        Assert.AreEqual(jsonReader.Value, double.PositiveInfinity);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
        Assert.AreEqual(jsonReader.Value, double.NegativeInfinity);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
      }
    }
    public void ReadConstructor()
    {
      string json = @"{""DefaultConverter"":new Date(0, ""hi""),""MemberConverter"":""1970-01-01T00:00:00Z""}";

      JsonReader reader = new JsonTextReader(new StringReader(json));

      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
      Assert.AreEqual("Date", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(0, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual("hi", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual("MemberConverter", reader.Value);
    }
    public void ParsingQuotedPropertyWithControlCharacters()
    {
      JsonReader reader = new JsonTextReader(new StringReader(@"{'hi\r\nbye':1}"));
      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual(@"hi
bye", reader.Value);
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.AreEqual(1, reader.Value);
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
      Assert.IsFalse(reader.Read());
    }
    public void ReadingEscapedStrings()
    {
      string input = "{value:'Purple\\r \\n monkey\\'s:\\tdishwasher'}";

      StringReader sr = new StringReader(input);

      using (JsonReader jsonReader = new JsonTextReader(sr))
      {
        Assert.AreEqual(0, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType);
        Assert.AreEqual(0, jsonReader.Depth);
        
        jsonReader.Read();
        Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
        Assert.AreEqual("Purple\r \n monkey's:\tdishwasher", jsonReader.Value);
        Assert.AreEqual('\'', jsonReader.QuoteChar);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.EndObject, jsonReader.TokenType);
        Assert.AreEqual(0, jsonReader.Depth);
      }
    }
    public void ReadLongJsonArray()
    {
      int valueCount = 10000;
      StringWriter sw = new StringWriter();
      JsonTextWriter writer = new JsonTextWriter(sw);
      writer.WriteStartArray();
      for (int i = 0; i < valueCount; i++)
      {
        writer.WriteValue(i);
      }
      writer.WriteEndArray();

      string json = sw.ToString();

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      Assert.IsTrue(reader.Read());
      for (int i = 0; i < valueCount; i++)
      {
        Assert.IsTrue(reader.Read());
        Assert.AreEqual(i, reader.Value);
      }
      Assert.IsTrue(reader.Read());
      Assert.IsFalse(reader.Read());
    }
    public void NullCharReading()
    {
      string json = "\0{\0'\0h\0i\0'\0:\0[\01\0,\0'\0'\0\0,\0null\0]\0,\0do\0:true\0}\0\0/*\0sd\0f\0*/\0/*\0sd\0f\0*/ \0";
      JsonTextReader reader = new JsonTextReader(new StringReader(json));

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Null, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Boolean, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);
      Assert.AreEqual("\0sd\0f\0", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);
      Assert.AreEqual("\0sd\0f\0", reader.Value);

      Assert.IsFalse(reader.Read());
    }
    public void ReadLongString()
    {
      string s = new string('a', 10000);
      JsonReader reader = new JsonTextReader(new StringReader("'" + s + "'"));
      reader.Read();

      Assert.AreEqual(s, reader.Value);
    }
 public void UnexpectedEndOfString()
 {
   JsonReader reader = new JsonTextReader(new StringReader("'hi"));
   reader.Read();
 }
    public void Depth()
    {
      string input = @"{
  value:'Purple',
  array:[1,2],
  subobject:{prop:1}
}";

      StringReader sr = new StringReader(input);

      using (JsonReader jsonReader = new JsonTextReader(sr))
      {
        Assert.AreEqual(0, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject);
        Assert.AreEqual(0, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
        Assert.AreEqual(jsonReader.Value, @"Purple");
        Assert.AreEqual(jsonReader.QuoteChar, '\'');
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Integer);
        Assert.AreEqual(1, jsonReader.Value);
        Assert.AreEqual(2, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Integer);
        Assert.AreEqual(2, jsonReader.Value);
        Assert.AreEqual(2, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(2, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.Integer);
        Assert.AreEqual(2, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
        Assert.AreEqual(1, jsonReader.Depth);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
        Assert.AreEqual(0, jsonReader.Depth);
      }
    }
    public void ReadingIndented()
    {
      string input = @"{
  CPU: 'Intel',
  Drives: [
    'DVD read/writer',
    ""500 gigabyte hard drive""
  ]
}";

      StringReader sr = new StringReader(input);

      using (JsonTextReader jsonReader = new JsonTextReader(sr))
      {
        jsonReader.SetCharBuffer(new char[5]);

        Assert.AreEqual(jsonReader.TokenType, JsonToken.None);
        Assert.AreEqual(0, jsonReader.LineNumber);
        Assert.AreEqual(0, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject);
        Assert.AreEqual(1, jsonReader.LineNumber);
        Assert.AreEqual(1, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(jsonReader.Value, "CPU");
        Assert.AreEqual(2, jsonReader.LineNumber);
        Assert.AreEqual(7, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(JsonToken.String, jsonReader.TokenType);
        Assert.AreEqual("Intel", jsonReader.Value);
        Assert.AreEqual(2, jsonReader.LineNumber);
        Assert.AreEqual(15, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName);
        Assert.AreEqual(jsonReader.Value, "Drives");
        Assert.AreEqual(3, jsonReader.LineNumber);
        Assert.AreEqual(10, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray);
        Assert.AreEqual(3, jsonReader.LineNumber);
        Assert.AreEqual(12, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
        Assert.AreEqual(jsonReader.Value, "DVD read/writer");
        Assert.AreEqual(jsonReader.QuoteChar, '\'');
        Assert.AreEqual(4, jsonReader.LineNumber);
        Assert.AreEqual(22, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.String);
        Assert.AreEqual(jsonReader.Value, "500 gigabyte hard drive");
        Assert.AreEqual(jsonReader.QuoteChar, '"');
        Assert.AreEqual(5, jsonReader.LineNumber);
        Assert.AreEqual(30, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
        Assert.AreEqual(6, jsonReader.LineNumber);
        Assert.AreEqual(4, jsonReader.LinePosition);

        jsonReader.Read();
        Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject);
        Assert.AreEqual(7, jsonReader.LineNumber);
        Assert.AreEqual(2, jsonReader.LinePosition);

        Assert.IsFalse(jsonReader.Read());
      }
    }
    public void ParseNumbers()
    {
      string json = @"[0,1,2 , 3]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));

      reader.Read();
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
    }
    public void ReadBytesFollowingNumberInObject()
    {
      string helloWorld = "Hello world!";
      byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

      JsonReader reader = new JsonTextReader(new StringReader(@"{num:1,data:'" + Convert.ToBase64String(helloWorldData) + @"'}"));
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.IsTrue(reader.Read());
      byte[] data = reader.ReadAsBytes();
      Assert.AreEqual(helloWorldData, data);
      Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
    public void AppendCharsWhileReadingNewLine()
    {
      string json = @"
{
  ""description"": ""A person"",
  ""type"": ""object"",
  ""properties"":
  {
    ""name"": {""type"":""string""},
    ""hobbies"": {
      ""type"": ""array"",
      ""items"": {""type"":""string""}
    }
  }
}
";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      reader.SetCharBuffer(new char[129]);

      for (int i = 0; i < 14; i++)
      {
        Assert.IsTrue(reader.Read());
      }

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("type", reader.Value);
    }
    public void ReadRandomJson()
    {
      string json = @"[
  true,
  {
    ""integer"": 99,
    ""string"": ""how now brown cow?"",
    ""array"": [
      0,
      1,
      2,
      3,
      4,
      {
        ""decimal"": 990.00990099
      },
      5
    ]
  },
  ""This is a string."",
  null,
  null
]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      while (reader.Read())
      {
        
      }
    }
    public void ReadNullTerminatorStrings()
    {
      JsonReader reader = new JsonTextReader(new StringReader("'h\0i'"));
      Assert.IsTrue(reader.Read());

      Assert.AreEqual("h\0i", reader.Value);
    }
    public void LongStringTest()
    {
      int length = 20000;
      string json = @"[""" + new string(' ', length) + @"""]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));

      reader.Read();
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual(typeof(string), reader.ValueType);
      Assert.AreEqual(20000, reader.Value.ToString().Length);

      reader.Read();
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      reader.Read();
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
    }
 public void UnexpectedEndOfHex()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"'h\u123"));
   reader.Read();
 }
    public void EscapedUnicodeText()
    {
      string json = @"[""\u003c"",""\u5f20""]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
      reader.SetCharBuffer(new char[2]);

      reader.Read();
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      reader.Read();
      Assert.AreEqual("<", reader.Value);

      reader.Read();
      Assert.AreEqual(24352, Convert.ToInt32(Convert.ToChar((string)reader.Value)));

      reader.Read();
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
    }
 public void UnexpectedEndOfControlCharacter()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"'h\"));
   reader.Read();
 }
    public void WriteToken()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader("[1,2,3,4,5]"));
      reader.Read();
      reader.Read();

      StringWriter sw = new StringWriter();
      JsonTextWriter writer = new JsonTextWriter(sw);
      writer.WriteToken(reader);

      Assert.AreEqual("1", sw.ToString());
    }
 public void ReadBytesNoStartWithUnexpectedEnd()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"[  "));
   Assert.IsTrue(reader.Read());
   reader.ReadAsBytes();
 }
 public void UnexpectedEndWhenParsingUnquotedProperty()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"{aww"));
   Assert.IsTrue(reader.Read());
   reader.Read();
 }
    public void ReadContentDelimitedByComments()
    {
      string json = @"/*comment*/{/*comment*/Name:/*comment*/true/*comment*/,/*comment*/
        ""ExpiryDate"":/*comment*/new
" + StringUtils.LineFeed +
@"Date
(/*comment*/null/*comment*/),
        ""Price"": 3.99,
        ""Sizes"":/*comment*/[/*comment*/
          ""Small""/*comment*/]/*comment*/}/*comment*/";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("Name", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
      Assert.AreEqual(true, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("ExpiryDate", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
      Assert.AreEqual(5, reader.LineNumber);
      Assert.AreEqual("Date", reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Null, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Comment, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
    }