Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从零开始的 JSON 库教程(一):启程解答篇 1. 修正 LEPT_PARSE_ROOT_NOT_SINGULAR #37

Closed
HongfeiXu opened this issue Oct 3, 2016 · 1 comment

Comments

@HongfeiXu
Copy link

HongfeiXu commented Oct 3, 2016

int lept_parse(lept_value* v, const char* json) {
    lept_context c;
    int ret;
    assert(v != NULL);
    c.json = json;
    v->type = LEPT_NULL;
    lept_parse_whitespace(&c);
    if ((ret = lept_parse_value(&c, v)) == LEPT_PARSE_OK) {
        lept_parse_whitespace(&c);
        if (*c.json != '\0')
            ret = LEPT_PARSE_ROOT_NOT_SINGULAR;
    }
    return ret;
}

老师好,不知道是不是找到了一个小纰漏, :>
因为在之前规定了lept_parse() 若失败,会把 v 设为 null 类型,所以我觉得,应该在判断JSON文本没有完结之后,加一句 v->type =LEPT_NULL,这样在 test_parse_root_not_singular() 函数中,可以正确 解析"false x"; 这类的情况。否则 EXPECT_EQ_INT(LEPT_NULL, lept_get_type(&v));将会打印错误信息。

@j178
Copy link

j178 commented Oct 3, 2016

参见 #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants