public void ReadBytesFailure() { JObject o = new JObject( new JProperty("Test1", 1) ); using (JTokenReader jsonReader = new JTokenReader(o)) { jsonReader.Read(); Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test1", jsonReader.Value); jsonReader.ReadAsBytes(); } }
public void ReadBytes() { byte[] data = Encoding.UTF8.GetBytes("Hello world!"); JObject o = new JObject( new JProperty("Test1", data) ); using (JTokenReader jsonReader = new JTokenReader(o)) { jsonReader.Read(); Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test1", jsonReader.Value); byte[] readBytes = jsonReader.ReadAsBytes(); Assert.AreEqual(data, readBytes); Assert.IsTrue(jsonReader.Read()); Assert.AreEqual(JsonToken.EndObject, jsonReader.TokenType); Assert.IsFalse(jsonReader.Read()); } }