我是靠谱客的博主 着急小丸子,这篇文章主要介绍c语言json 5c,json_object_to_json_string在'c'中返回值WITHOUT引號,现在分享给大家,希望可以做个参考。

我正在嘗試一些應該很簡單的事情。我想從Mongo中返回一個返回的JSON值,並驗證這個值是我期待的。爲此,我使用json_object_to_json_string返回json輸出的字符串值。json_object_to_json_string在'c'中返回值WITHOUT引號

問題是字符串正在用雙引號圍繞該值返回:返回EX「562416504bacd3940b8b2d5c」而不是562416504bacd3940b8b2d5c。

然後這阻止我能夠做一個簡單的匹配(見下文)。

反正有沒有惱人的雙引號得到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 samenn");

}

else

{

printf("nids are NOT the same %s %snn",account_id,account_id_fromSession);

}

輸出的代碼:

ids are NOT the same 562416504bacd3940b8b2d5c "562416504bacd3940b8b2d5c"

最后

以上就是着急小丸子最近收集整理的关于c语言json 5c,json_object_to_json_string在'c'中返回值WITHOUT引號的全部内容,更多相关c语言json内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部