Fix exception parsing empty JSON arrays.

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

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

Loading…
Cancel
Save