当前位置: 首页>>代码示例>>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;未经允许,请勿转载。