Fix exception parsing empty JSON arrays.

master
Glenn Maynard 5 years ago
parent 63f7aa5beb
commit 80b08dbe0c
  1. 27
      smx-config/SMXJSON.cs

@ -360,22 +360,25 @@ namespace SMXJSON
List<Object> result = new List<Object>();
while(true)
{
Object value = ParseJSONValue(reader);
result.Add(value);
SkipWhitespace(reader);
int nextCharacter = reader.Read();
switch(nextCharacter)
if(reader.Peek() == ']')
{
case ']':
reader.Read();
return result;
case ',':
continue;
case -1:
throw new ParseError(reader, "Unexpected EOF reading array");
default:
throw new ParseError(reader, "Unexpected token " + nextCharacter + " reading array");
}
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);
result.Add(value);
}
}
static private Dictionary<string, Object> ReadJSONDictionary(StringReader reader)

Loading…
Cancel
Save