Method: Oj::Parser#parse

Defined in:
ext/oj/parser.c

#parse(json) ⇒ Object

Parse a JSON string.

Returns the result according to the delegate of the parser.



1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
# File 'ext/oj/parser.c', line 1116

static VALUE parser_parse(VALUE self, VALUE json) {
    ojParser    p;
    const byte *ptr = (const byte *)StringValuePtr(json);

    TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);

    parser_reset(p);
    p->start(p);
    parse(p, ptr);

    if (0 < p->depth) {
        if (OBJECT_FUN == p->stack[p->depth]) {
            parse_error(p, "Object is not closed");
        } else {
            parse_error(p, "Array is not closed");
        }
    }
    return p->result(p);
}