當前位置: 首頁>>代碼示例>>C#>>正文


C# JsonTextReader.SetCharBuffer方法代碼示例

本文整理匯總了C#中Newtonsoft.Json.JsonTextReader.SetCharBuffer方法的典型用法代碼示例。如果您正苦於以下問題:C# JsonTextReader.SetCharBuffer方法的具體用法?C# JsonTextReader.SetCharBuffer怎麽用?C# JsonTextReader.SetCharBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Newtonsoft.Json.JsonTextReader的用法示例。


在下文中一共展示了JsonTextReader.SetCharBuffer方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AppendCharsWhileReadingNewLine

    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));
#if DEBUG
      reader.SetCharBuffer(new char[129]);
#endif

      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);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:31,代碼來源:JsonTextReaderTest.cs

示例2: ReadingIndented

    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))
      {
#if DEBUG
        jsonReader.SetCharBuffer(new char[5]);
#endif

        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());
      }
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:77,代碼來源:JsonTextReaderTest.cs

示例3: AppendCharsWhileReadingNull

    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));
#if DEBUG
      reader.SetCharBuffer(new char[129]);
#endif

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

      reader.Read();
      Assert.AreEqual(JsonToken.Null, reader.TokenType);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:34,代碼來源:JsonTextReaderTest.cs

示例4: ParseNullStringConstructor

    public void ParseNullStringConstructor()
    {
      string json = "new Date\0()";
      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[7]);
#endif

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

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:15,代碼來源:JsonTextReaderTest.cs

示例5: ParseAdditionalContent_Text

    public void ParseAdditionalContent_Text()
    {
      string json = @"[
""Small"",
""Medium"",
""Large""
]content";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[2]);
#endif

      reader.Read();
      Assert.AreEqual(1, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(2, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(3, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(4, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(5, reader.LineNumber);

      ExceptionAssert.Throws<JsonReaderException>(
        "Additional text encountered after finished reading JSON content: c. Path '', line 5, position 2.",
        () =>
          {
            reader.Read();
          });
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:35,代碼來源:JsonTextReaderTest.cs

示例6: ReadBufferOnEndComment

    public void ReadBufferOnEndComment()
    {
      string json = @"/*comment*/ { /*comment*/
        ""Name"": /*comment*/ ""Apple"" /*comment*/, /*comment*/
        ""ExpiryDate"": ""\/Date(1230422400000)\/"",
        ""Price"": 3.99,
        ""Sizes"": /*comment*/ [ /*comment*/
          ""Small"", /*comment*/
          ""Medium"" /*comment*/,
          /*comment*/ ""Large""
        /*comment*/ ] /*comment*/
      } /*comment*/";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[5]);
#endif

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

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

      Assert.IsFalse(reader.Read());
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:28,代碼來源:JsonTextReaderTest.cs

示例7: ReadBufferOnControlChar

    public void ReadBufferOnControlChar()
    {
      string json = @"[
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  },
  {
    ""Name"": ""Jim"",
    ""BirthDate"": ""\/Date(978048000000)\/"",
    ""LastModified"": ""\/Date(978048000000)\/""
  }
]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[5]);
#endif

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

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(new DateTime(631136448000000000), reader.Value);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:28,代碼來源:JsonTextReaderTest.cs

示例8: ReadUnicode

    public void ReadUnicode()
    {
      string json = @"{""Message"":""Hi,I\u0092ve send you smth""}";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[5]);
#endif

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

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

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual(@"Hi,I" + '\u0092' + "ve send you smth", reader.Value);

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

      Assert.IsFalse(reader.Read());
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:25,代碼來源:JsonTextReaderTest.cs

示例9: EscapedUnicodeText

    public void EscapedUnicodeText()
    {
      string json = @"[""\u003c"",""\u5f20""]";

      JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
      reader.SetCharBuffer(new char[2]);
#endif

      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);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:21,代碼來源:JsonTextReaderTest.cs

示例10: ParseAdditionalContent_Text

    public void ParseAdditionalContent_Text()
    {
      string json = @"[
""Small"",
""Medium"",
""Large""
]content";

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

      reader.Read();
      Assert.AreEqual(1, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(2, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(3, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(4, reader.LineNumber);

      reader.Read();
      Assert.AreEqual(5, reader.LineNumber);

      reader.Read();
    }
開發者ID:plurby,項目名稱:Newtonsoft.Json,代碼行數:28,代碼來源:JsonTextReaderTest.cs


注:本文中的Newtonsoft.Json.JsonTextReader.SetCharBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。