Fix exception parsing empty JSON arrays.
This commit is contained in:
parent
63f7aa5beb
commit
80b08dbe0c
@ -360,22 +360,25 @@ namespace SMXJSON
|
|||||||
List<Object> result = new List<Object>();
|
List<Object> result = new List<Object>();
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
SkipWhitespace(reader);
|
||||||
|
if(reader.Peek() == ']')
|
||||||
|
{
|
||||||
|
reader.Read();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result.Count > 0)
|
||||||
|
{
|
||||||
|
int comma = reader.Read();
|
||||||
|
if(comma == -1)
|
||||||
|
throw new ParseError(reader, "Unexpected EOF reading array");
|
||||||
|
if(comma != ',')
|
||||||
|
throw new ParseError(reader, "Expected ',', got " + comma + " reading array");
|
||||||
|
SkipWhitespace(reader);
|
||||||
|
}
|
||||||
|
|
||||||
Object value = ParseJSONValue(reader);
|
Object value = ParseJSONValue(reader);
|
||||||
result.Add(value);
|
result.Add(value);
|
||||||
|
|
||||||
SkipWhitespace(reader);
|
|
||||||
int nextCharacter = reader.Read();
|
|
||||||
switch(nextCharacter)
|
|
||||||
{
|
|
||||||
case ']':
|
|
||||||
return result;
|
|
||||||
case ',':
|
|
||||||
continue;
|
|
||||||
case -1:
|
|
||||||
throw new ParseError(reader, "Unexpected EOF reading array");
|
|
||||||
default:
|
|
||||||
throw new ParseError(reader, "Unexpected token " + nextCharacter + " reading array");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static private Dictionary<string, Object> ReadJSONDictionary(StringReader reader)
|
static private Dictionary<string, Object> ReadJSONDictionary(StringReader reader)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user