使用nlohmann json将整数列表解压缩到std :: vector <int>

i

我正在使用https://github.com/nlohmann/json

这很棒。

但是..有什么方法可以解压:

{
    "my_list" : [1,2,3]
}

std:vector<int>

我找不到任何提及,但std::vector<int> v = j["my_list"];失败了,j["my_list"].get<std::vector<int>>()

交叉链接到https://github.com/nlohmann/json/issues/1460

i

因此,它确实工作。我没有隔离测试用例,并且我的JSON字符串格式错误。

所以,

json J(json_string);
J["my_list"].get<std::vector<int>>()

确实有效。

就我而言,我确保我的C ++变量名与JSON键匹配,因此我可以简单地使用宏:

#define EXTRACT(x) x = J[#x].get< decltype(x) >()

int foo;
std::vector<float> bar;

EXTRACT(foo);
EXTRACT(bar);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将文件从Boost filter_streambuf解压缩到std :: vector <unsigned char>?

尝试在类中使用 vector<vector<int>>

std :: vector <int>到std :: vector <enum>

将列表解压缩到元组的中间

使用 char 访问 vector<int>

将std :: tuple解压缩到原位,而无需使用std :: index_sequence的人工层

使用phtread_exit返回std :: pair <vector <int>,double>

使用nlohmann在cpp中输出Json数组

如何使用nlohmann lib解析json?

如何使用循环将向量推入queue <vector <int >>?

不匹配调用 '(std::vector<std::vector<int> >) (int, std::vector<int>)'

将vector <int>强制转换为const vector <const int>

将 int[n][n] 转换为 vector<vector<int>>

从逗号分隔的整数解析std :: vector <int>

emplace_back无法与std :: vector <std :: map <int,int >>一起使用

如何使用单个for循环遍历std :: map <string,int>和std :: vector <int>?

将vector <int>转换为整数

使用初始化器列表作为值时,无法插入std :: list <std :: vector <int >>?

将std :: vector <int>保存到文件

使用boost将gzip压缩/解压缩到内存中

使用std :: optional通过引用将std :: vector <int>传递给函数

C ++:错误无法从std :: vector <int> *转换为std :: vector <std :: vector <int>>

我可以将std :: vector <int> *转换为int *吗?

在C ++上使用vector <vector <int >>进行的矩阵读取错误

如何使用SQL将摘要表解压缩为单独的记录?

正确使用 vector<int>::size_type

使用Google Test测试Map <int,vector>

.NET 3.5如何使用DotNetZip将ZIP文件解压缩到指定位置

如何使用powershell将tar文件解压缩到特定文件夹