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


C# JsonTextReader.ReadAsBytes方法代碼示例

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


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

示例1: ReadBytesWithBadCharacter

 public void ReadBytesWithBadCharacter()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"true"));
   reader.ReadAsBytes();
 }
開發者ID:plurby,項目名稱:Newtonsoft.Json,代碼行數:5,代碼來源:JsonTextReaderTest.cs

示例2: ReadBytesWithUnexpectedEnd

    public void ReadBytesWithUnexpectedEnd()
    {
      string helloWorld = "Hello world!";
      byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

      JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));

      ExceptionAssert.Throws<JsonReaderException>(
        "Unterminated string. Expected delimiter: '. Path '', line 1, position 17.",
        () =>
          {
            reader.ReadAsBytes();
          });
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:14,代碼來源:JsonTextReaderTest.cs

示例3: ReadBytesEmptyWrappedObject

        public void ReadBytesEmptyWrappedObject()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"{}"));

            ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Error reading bytes. Unexpected token: StartObject. Path '', line 1, position 2." );
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:6,代碼來源:ExceptionHandlingTests.cs

示例4: ReadAsBytesIntegerArrayWithComments

    public void ReadAsBytesIntegerArrayWithComments()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[/*hi*/1/*hi*/,2/*hi*/]"));

      byte[] data = reader.ReadAsBytes();
      Assert.AreEqual(2, data.Length);
      Assert.AreEqual(1, data[0]);
      Assert.AreEqual(2, data[1]);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:9,代碼來源:JsonTextReaderTest.cs

示例5: ReadAsBytesArrayWithBadContent

    public void ReadAsBytesArrayWithBadContent()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[1.0]"));

      ExceptionAssert.Throws<JsonReaderException>(
        "Unexpected token when reading bytes: Float. Path '[0]', line 1, position 4.",
        () =>
        {
          reader.ReadAsBytes();
        });
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:11,代碼來源:JsonTextReaderTest.cs

示例6: ReadSingleBytes

    public void ReadSingleBytes()
    {
      StringReader s = new StringReader(@"""SGVsbG8gd29ybGQu""");
      JsonTextReader reader = new JsonTextReader(s);

      byte[] data = reader.ReadAsBytes();
      Assert.IsNotNull(data);

      string text = Encoding.UTF8.GetString(data, 0, data.Length);
      Assert.AreEqual("Hello world.", text);
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:11,代碼來源:JsonTextReaderTest.cs

示例7: ReadAsBytesNoContentWrappedObject

    public void ReadAsBytesNoContentWrappedObject()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"{"));

      ExceptionAssert.Throws<JsonReaderException>(
        "Unexpected end when reading bytes. Path '', line 1, position 1.",
        () =>
        {
          reader.ReadAsBytes();
        });
    }
開發者ID:robertherber,項目名稱:PersonalTasks,代碼行數:11,代碼來源:JsonTextReaderTest.cs

示例8: ReadBytesNoStartWithUnexpectedEnd

 public void ReadBytesNoStartWithUnexpectedEnd()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"[  "));
   Assert.IsTrue(reader.Read());
   reader.ReadAsBytes();
 }
開發者ID:runegri,項目名稱:Applicable,代碼行數:6,代碼來源:JsonTextReaderTest.cs

示例9: ReadAsBytes_Base64AndGuid

        public void ReadAsBytes_Base64AndGuid()
        {
            JsonTextReader jsonTextReader = new JsonTextReader(new StringReader("'AAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA'"));
            byte[] data = jsonTextReader.ReadAsBytes();
            byte[] expected = Convert.FromBase64String("AAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA");

            CollectionAssert.AreEqual(expected, data);

            jsonTextReader = new JsonTextReader(new StringReader("'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAABAAAA'"));
            data = jsonTextReader.ReadAsBytes();
            expected = new Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAABAAAA").ToByteArray();

            CollectionAssert.AreEqual(expected, data);
        }
開發者ID:ruisebastiao,項目名稱:Newtonsoft.Json,代碼行數:14,代碼來源:JsonTextReaderTest.cs

示例10: ReadAsBytes_CommaErrors_Multiple

        public void ReadAsBytes_CommaErrors_Multiple()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader("['',,'']"));
            reader.Read();
            CollectionAssert.AreEquivalent(new byte[0], reader.ReadAsBytes());

            ExceptionAssert.Throws<JsonReaderException>(() =>
            {
                reader.ReadAsBytes();
            }, "Unexpected character encountered while parsing value: ,. Path '[1]', line 1, position 5.");

            CollectionAssert.AreEquivalent(new byte[0], reader.ReadAsBytes());
            Assert.IsTrue(reader.Read());
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:14,代碼來源:ExceptionHandlingTests.cs

示例11: ReadBytesWithBadCharacter

        public void ReadBytesWithBadCharacter()
        {
            JsonReader reader = new JsonTextReader(new StringReader(@"true"));

            ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: t. Path '', line 1, position 1.");
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:6,代碼來源:ExceptionHandlingTests.cs

示例12: ReadAsBytes_InvalidEndArray

        public void ReadAsBytes_InvalidEndArray()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader("]"));

            ExceptionAssert.Throws<JsonReaderException>(() =>
            {
                reader.ReadAsBytes();
            }, "Unexpected character encountered while parsing value: ]. Path '', line 1, position 1.");
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:9,代碼來源:ExceptionHandlingTests.cs

示例13: ReadAsBytesBadContent

        public void ReadAsBytesBadContent()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));

            ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: e. Path '', line 1, position 2.");
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:6,代碼來源:ExceptionHandlingTests.cs

示例14: ReadAsBytes_BadData

        public void ReadAsBytes_BadData()
        {
            string json = @"pie";

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

            ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
        }
開發者ID:JamesNK,項目名稱:Newtonsoft.Json,代碼行數:8,代碼來源:ExceptionHandlingTests.cs

示例15: ReadBytesWithUnexpectedEnd

    public void ReadBytesWithUnexpectedEnd()
    {
      string helloWorld = "Hello world!";
      byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

      JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));
      reader.ReadAsBytes();
    }
開發者ID:plurby,項目名稱:Newtonsoft.Json,代碼行數:8,代碼來源:JsonTextReaderTest.cs


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