private static JObject ParseObject(TextReader reader, int max_nest) { SkipSpace(reader); if (reader.Read() != BEGIN_OBJECT) { throw new FormatException(); } JObject obj = new JObject(); SkipSpace(reader); if (reader.Peek() != END_OBJECT) { while (true) { string name = JString.Parse(reader).Value; if (obj.Properties.ContainsKey(name)) { throw new FormatException(); } SkipSpace(reader); if (reader.Read() != NAME_SEPARATOR) { throw new FormatException(); } JObject value = Parse(reader, max_nest - 1); obj.Properties.Add(name, value); SkipSpace(reader); char nextchar = (char)reader.Read(); if (nextchar == VALUE_SEPARATOR) { continue; } if (nextchar == END_OBJECT) { break; } throw new FormatException(); } } else { reader.Read(); } return(obj); }
public static JObject Parse(TextReader reader, int max_nest = 100) { if (max_nest < 0) { throw new FormatException(); } SkipSpace(reader); char firstChar = (char)reader.Peek(); if (firstChar == LITERAL_FALSE[0]) { return(JBoolean.ParseFalse(reader)); } if (firstChar == LITERAL_NULL[0]) { return(ParseNull(reader)); } if (firstChar == LITERAL_TRUE[0]) { return(JBoolean.ParseTrue(reader)); } if (firstChar == BEGIN_OBJECT) { return(ParseObject(reader, max_nest)); } if (firstChar == BEGIN_ARRAY) { return(JArray.Parse(reader, max_nest)); } if ((firstChar >= '0' && firstChar <= '9') || firstChar == '-') { return(JNumber.Parse(reader)); } if (firstChar == QUOTATION_MARK) { return(JString.Parse(reader)); } throw new FormatException(); }