/// <summary> /// 测试值的类型,光标将会跳过空白,但不会跳过值开始第一个字符 /// </summary> /// <param name="str"></param> /// <param name="offset"></param> /// <param name="line"></param> /// <param name="column"></param> /// <returns></returns> private ObjectTypes TestValueType(SimpleReader reader) { var c = reader.Peek(true); switch (c) { case '[': return(ObjectTypes.Array); case '{': return(ObjectTypes.Object); case '\"': return(ObjectTypes.String); default: if (c == 't' && reader.TestString("true", false)) { return(ObjectTypes.Boolean); } else if (c == 'f' && reader.TestString("false", false)) { return(ObjectTypes.Boolean); } else if (c >= '0' && c <= '9') { return(ObjectTypes.Number); } break; } throw new ParseException("无法识别的类型", reader); }
/// <summary> /// 读取 true/false 字符串。 /// 要求光标必须放在 t 或是 false 上面 /// </summary> /// <param name="reader"></param> /// <returns></returns> private string ReadBooleanValue(SimpleReader reader) { if (reader.TestString("true", true)) { return("true"); } else if (reader.TestString("false", true)) { return("false"); } throw new ParseException("ReadBooleanValue异常", reader); }