json#u object_to#u json_字符串返回值,在';c';

json#u object_to#u json_字符串返回值,在';c';,c,json,regex,mongodb,gcc,C,Json,Regex,Mongodb,Gcc,我正在尝试一些应该简单的事情。我想从Mongo返回的JSON中捕获一个值,并验证该值是否符合我的预期。为此,我使用json_object_To_json_string返回json输出的字符串值 问题是返回的字符串中包含双引号:返回的是EX“562416504bacd3940b8b2d5c”,而不是562416504bacd3940b8b2d5c 这样我就无法进行简单的if匹配(见下文) 有没有任何方法可以在不使用恼人的双引号的情况下获取json值 struct json_object *new_

我正在尝试一些应该简单的事情。我想从Mongo返回的JSON中捕获一个值,并验证该值是否符合我的预期。为此,我使用json_object_To_json_string返回json输出的字符串值

问题是返回的字符串中包含双引号:返回的是EX“562416504bacd3940b8b2d5c”,而不是562416504bacd3940b8b2d5c

这样我就无法进行简单的if匹配(见下文)

有没有任何方法可以在不使用恼人的双引号的情况下获取json值

struct json_object *new_obj;

// Fetch document
while (mongoc_cursor_next (cursor, &doc)) 
{
char *docAsJSON = bson_as_json (doc, NULL);

// Grab account_id from session table
new_obj = json_tokener_parse(docAsJSON);
new_obj = json_object_object_get(new_obj, "account_id");
char * account_id_fromSession = json_object_to_json_string(new_obj);

if (strcmp(account_id,account_id_fromSession) == 0)
    {
    printf("\nids are the same\n\n");
    }
else
    {
    printf("\nids are NOT the same %s %s\n\n",account_id,account_id_fromSession);
    }   
代码输出:

ids are NOT the same 562416504bacd3940b8b2d5c "562416504bacd3940b8b2d5c"
我有一个“犹太人区”的解决方案,但我想要比字符串替换更优雅的东西

void remove_all_chars(char* str, char c) 
{
char *pr = str, *pw = str;
while (*pr) 
    {
    *pw = *pr++;
    pw += (*pw != c);
    }
*pw = '\0';
}

// Remove " from token
remove_all_chars(account_id_fromSession, '"');

感谢@dasblinkenlight通过此代码的另一个问题

而不是类似于json stringify()的
json\u object\u to\u json\u string()
,使用返回字符串的
json\u object\u get\u string()