我有以下代码
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <json/json.h>
int main(int argc, char **argv)
{
json_object *new_obj;
char buf[] = "{ \"foo\": \"bar\", \"foo2\": \"bar2\", \"foo3\": \"bar3\" }";
new_obj = json_tokener_parse(buf);
.....
json_object_put(new_obj);
}
Run Code Online (Sandbox Code Playgroud)
是否json_object_put(new_obj)释放所有内存相关new_obj?
我正在尝试使用 json.push_back 调用将 64 位整数数据推送到 JSONNode
uint64_t myHigh = 0x10;
uint64_t myLow = 0x12;
uint64_t myFinal = 0;
myFinal = (myHigh << 32) | myLow ;
std::cout << "val = 0x" << std::hex << myFinal << "\n";-----(1)
JSONNode jvData;
jvData.push_back(JSONNode("value",myFinal));
std::cout<<jvData.write();--------------------------(2)
Run Code Online (Sandbox Code Playgroud)
cout (1) 给出值 0xa0000000c cout (2) 显示值 12。
我预计 cout (2) 值为 42949672972 但似乎没有按预期工作
Json支持64位int吗?
我想用libJSON创建一个数组JSONNode.我尝试了以下,但它不起作用:
JSONNode array;
JSONNode foo("word", "foo");
JSONNode bar("word", "bar");
array.push_back(foo);
array.push_back(bar);
Run Code Online (Sandbox Code Playgroud)
这导致:
{
"word": "foo",
"word": "bar"
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
[
{"word": "foo"},
{"word": "bar"}
]
Run Code Online (Sandbox Code Playgroud)
我很清楚,我没有指定我想要一个数组.问题是,我搜索了图书馆并搜索了一下,但我发现无法做到这一点.有人可以帮我解决这个问题吗?
(旁注:我想添加一个"libjson"标签,但这似乎还不存在,似乎.)
我有以下代码
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <json/json.h>
int main(int argc, char **argv)
{
json_object *new_obj;
char buf[] = "{ \"foo\": \"bar\", \"foo2\": \"bar2\", \"foo3\": \"bar3\" }"
new_obj = json_tokener_parse(buf);
printf("The value of foo is %s" /*What I have to put here?*/);
printf("The value of foo2 is %s" /*What I have to put here?*/);
printf("The value of foo3 is %s" /*What I have to put here?*/);
json_object_put(new_obj);
}
Run Code Online (Sandbox Code Playgroud)
我知道我们必须用来json_tokener_parse()解析json字符串,但后来我不知道如何从json_object中提取值,new_obj如上面代码中的注释所示
如何获得json值 json_tokener_parse()?