我正在尝试解析JSON文件中的数组,如下所示
{
"val": [5,6]
}使用从库中包含的parse_config.c中改编的以下代码,
char errbuf[1024];
yajl_val node;
long length;
char *file_data = read_file(&length, "conf.json");
node = yajl_tree_parse((const char *) file_data, errbuf, sizeof(errbuf));
const char *path[] = {"val", (const char *) 0};
yajl_val v = yajl_tree_get(node, path, yajl_t_number);
if (v)
printf("Node found.\n");
else
printf("Can't find node %s\n", path[0]);
yajl_tree_free(node);
free(file_data);这种方法对于单个值是成功的。
{
"val": 5
}(我的意思是填充v并打印Node found. ),但不是用于数组。对于解析数组,我需要做什么不同的操作?
谢谢。
发布于 2018-01-24 04:18:19
https://stackoverflow.com/questions/36844987
复制相似问题