当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextReader.ReadAsBytes方法代码示例

本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextReader.ReadAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.ReadAsBytes方法的具体用法?C# JsonTextReader.ReadAsBytes怎么用?C# JsonTextReader.ReadAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Imports.Newtonsoft.Json.JsonTextReader的用法示例。


在下文中一共展示了JsonTextReader.ReadAsBytes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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:WimVergouwe,项目名称:ravendb,代码行数:14,代码来源:JsonTextReaderTest.cs

示例2: ReadBytesNoStartWithUnexpectedEnd

    public void ReadBytesNoStartWithUnexpectedEnd()
    {
      JsonReader reader = new JsonTextReader(new StringReader(@"[  "));
      Assert.IsTrue(reader.Read());

      Assert.IsNull(reader.ReadAsBytes());
      Assert.AreEqual(JsonToken.None, reader.TokenType);
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:8,代码来源:JsonTextReaderTest.cs

示例3: 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:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例4: ReadBytesWithBadCharacter

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

      ExceptionAssert.Throws<JsonReaderException>(
        "Error reading bytes. Unexpected token: Boolean. Path '', line 1, position 4.",
        () =>
          {
            reader.ReadAsBytes();
          });
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例5: ReadBytesFollowingNumberInObject

    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();
      CollectionAssert.AreEquivalent(helloWorldData, data);
      Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:20,代码来源:JsonTextReaderTest.cs

示例6: 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:WimVergouwe,项目名称:ravendb,代码行数:9,代码来源:JsonTextReaderTest.cs

示例7: ReadAsBytesIntegerArrayWithNoEnd

    public void ReadAsBytesIntegerArrayWithNoEnd()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[1"));

      ExceptionAssert.Throws<JsonReaderException>(
        "Unexpected end when reading bytes. Path '[0]', line 1, position 2.",
        () =>
        {
          reader.ReadAsBytes();
        });
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例8: 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:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例9: ReadAsBytesBadContent

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

      ExceptionAssert.Throws<JsonReaderException>(
        "Error reading bytes. Unexpected token: StartConstructor. Path '', line 1, position 9.",
        () =>
        {
          reader.ReadAsBytes();
        });
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例10: ReadAsBytesNoContent

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

      Assert.IsNull(reader.ReadAsBytes());
      Assert.AreEqual(JsonToken.None, reader.TokenType);
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:7,代码来源:JsonTextReaderTest.cs

示例11: 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:WimVergouwe,项目名称:ravendb,代码行数:11,代码来源:JsonTextReaderTest.cs

示例12: ReadBytesAsStreamShouldPreserveJsonTextReaderInternalState

        public void ReadBytesAsStreamShouldPreserveJsonTextReaderInternalState(int size)
        {
            var random = new Random(size);

            var buffer = new byte[size];
            var items = new Data[3];
            for (int i = 0; i < 3; i++)
            {
                random.NextBytes(buffer);
                items[i] = new Data
                {
                    Foo = buffer.ToArray()
                };
            }

            var jsonObj = RavenJToken.FromObject(items);

            var jsonObjAsString = jsonObj.ToString();

            using (var textReader = new StringReader(jsonObjAsString))
            using (var jsonReader = new JsonTextReader(textReader))
            {
                jsonReader.Read(); //start array

                jsonReader.Read();
                jsonReader.Read(); // property name
                var actual = new byte[buffer.Length];
                buffer = items[0].Foo;
                using (var objectStream = jsonReader.ReadBytesAsStream())
                {
                    objectStream.Read(actual, 0, actual.Length);

                    for (int a = 0; a < actual.Length; a++)
                    {
                        if (buffer[a] != actual[a])
                        {
                            Assert.True(false, "not equal on byte " + a);
                        }
                    }
                }

                jsonReader.Read(); //end object

                jsonReader.Read(); //start object
                jsonReader.Read(); // property name				
                actual = jsonReader.ReadAsBytes(); //	value;
                buffer = items[1].Foo;
                for (int a = 0; a < actual.Length; a++)
                {
                    if (buffer[a] != actual[a])
                    {
                        Assert.True(false, "not equal on byte " + a);
                    }
                }

                jsonReader.Read(); //end object


                jsonReader.Read(); //start object
                jsonReader.Read(); // property name
                actual = new byte[buffer.Length];
                buffer = items[2].Foo;
                using (var objectStream = jsonReader.ReadBytesAsStream())
                {
                    objectStream.Read(actual, 0, actual.Length);

                    for (int a = 0; a < actual.Length; a++)
                    {
                        if (buffer[a] != actual[a])
                        {
                            Assert.True(false, "not equal on byte " + a);
                        }
                    }
                }

                jsonReader.Read(); //end object

            }
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:79,代码来源:RavenDB-4196.cs

示例13: ReadBytesWithError

        public void ReadBytesWithError()
        {
            string json = @"{
    ChildId: '123'
}";

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

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

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

            try
            {
                jsonTextReader.ReadAsBytes();
            }
            catch (FormatException)
            {
            }

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

            Assert.IsFalse(jsonTextReader.Read());
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:27,代码来源:JsonTextReaderTest.cs


注:本文中的Raven.Imports.Newtonsoft.Json.JsonTextReader.ReadAsBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。