-Fixed ReadAsBytes with type name handling

This commit is contained in:
James Newton-King
2016-01-08 22:37:05 +13:00
parent 2c5322c302
commit 70120ce077
4 changed files with 91 additions and 2 deletions
+13 -1
View File
@@ -449,6 +449,7 @@ namespace Newtonsoft.Json
public override byte[] ReadAsBytes()
{
EnsureBuffer();
bool isWrappedArray = false;
switch (_currentState)
{
@@ -475,11 +476,22 @@ namespace Newtonsoft.Json
case '"':
case '\'':
ParseString(currentChar, ReadType.ReadAsBytes);
return (byte[])Value;
byte[] data = (byte[])Value;
if (isWrappedArray)
{
ReaderReadAndAssert();
if (TokenType != JsonToken.EndObject)
{
throw JsonReaderException.Create(this, "Error reading bytes. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, TokenType));
}
SetToken(JsonToken.Bytes, data, false);
}
return data;
case '{':
_charPos++;
SetToken(JsonToken.StartObject);
ReadIntoWrappedTypeObject();
isWrappedArray = true;
break;
case '[':
_charPos++;