Nov11 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

lacks ending quotation before the end of string #120

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi

I'm getting 'lacks ending quotation before the end of string' error in line 
document.ParseInsitu<0>(buffer).HasParseError()

Here is my code

Document document;

#if 0
    // "normal" parsing, decode strings to new buffers. Can use other input stream via ParseStream().
    if (document.Parse<0>(json).HasParseError())
        return 1;
#else
    // In-situ parsing, decode strings directly in the source string. Source must be string.
    char buffer[sizeof(json_string)];
    memcpy(buffer, json_string, sizeof(json_string));
    if (document.ParseInsitu<0>(buffer).HasParseError())
    {
        const char * error = document.ParseInsitu<0>(buffer).GetParseError();
        return "";
    }

#endif

    if (!document.IsNull())
    {
        if (document.HasMember("access_token"))
        {
            return document["access_token"].GetString();
        }
    }

and here is the json

{
    "access_token": "mytoken",
    "expires_in": 3600,
    "token_type": "Bearer",
    "scope": "token",
    "refresh_token": "mytoken"
}

It's valid json.

Please advise!

Original issue reported on code.google.com by ggilo...@gmail.com on 31 Mar 2015 at 9:06

GoogleCodeExporter commented 8 years ago
What's the definition of "json_string"? Maybe your "sizeof(json_string)" if 
wrong?

The parsing code you used is copied from the tutorial. But (mem)copying the 
buffer before doing insitu parsing usually doesn't make much sense in real 
code. I'd suggest that you just do the "normal" parsing instead.

Original comment by philipp....@gmail.com on 3 Apr 2015 at 8:34