Beispiel #1
0
void JsonIn::skip_value()
{
    char ch;
    eat_whitespace();
    ch = peek();
    // it's either a string '"'
    if (ch == '"') {
        skip_string();
    // or an object '{'
    } else if (ch == '{') {
        skip_object();
    // or an array '['
    } else if (ch == '[') {
        skip_array();
    // or a number (-0123456789)
    } else if (ch == '-' || (ch >= '0' && ch <= '9')) {
        skip_number();
    // or "true", "false" or "null"
    } else if (ch == 't') {
        skip_true();
    } else if (ch == 'f') {
        skip_false();
    } else if (ch == 'n') {
        skip_null();
    // or an error.
    } else {
        std::stringstream err;
        err << "expected JSON value but got '" << ch << "'";
        error(err.str());
    }
    // skip_* end value automatically
}
Beispiel #2
0
bool JsonIn::skip_value()
{
    char ch;
    bool foundsep;
    eat_whitespace();
    ch = peek();
    // it's either a string '"'
    if (ch == '"') {
        foundsep = skip_string();
    // or an object '{'
    } else if (ch == '{') {
        foundsep = skip_object();
    // or an array '['
    } else if (ch == '[') {
        foundsep = skip_array();
    // or a number (-0123456789)
    } else if (ch == '-' || (ch >= '0' && ch <= '9')) {
        foundsep = skip_number();
    // or "true", "false" or "null"
    } else if (ch == 't') {
        foundsep = skip_true();
    } else if (ch == 'f') {
        foundsep = skip_false();
    } else if (ch == 'n') {
        foundsep = skip_null();
    // or an error.
    } else {
        std::stringstream err;
        err << line_number() << ": expected JSON value but got '" << ch << "'";
        throw err.str();
    }
    return foundsep;//b( foundsep || skip_separator() );
}
Beispiel #3
0
json_value_type JsonIn::get_next_type()
{
    json_value_type jvt = JVT_UNKNOWN;

    char ch;
    eat_whitespace();
    ch = peek();

    // it's either a string '"'
    if (ch == '"') {
        jvt = JVT_STRING;
    // or an object '{'
    } else if (ch == '{') {
        jvt = JVT_OBJECT;
    // or an array '['
    } else if (ch == '[') {
        jvt = JVT_ARRAY;
    // or a number (-0123456789)
    } else if (ch == '-' || (ch >= '0' && ch <= '9')) {
        jvt = JVT_NUMBER;
    // or "true", "false" or "null"
    } else if (ch == 't' || ch == 'f') {
        try{
            get_bool();
            jvt = JVT_BOOL;
        }catch(std::string ex){
            // nothing to do, jvt is still JVT_UNKNOWN
        }
    } else if (ch == 'n') {
        try{
            skip_null();
            jvt = JVT_NULL;
        }catch(std::string ex){
            // nothing to do, jvt is still JVT_UNKNOWN
        }
    }

    return jvt;
}