39得票2回答
C++:使用nlohmann json从文件中读取json对象

我正在使用nlohmann的json库在C ++中处理JSON对象。最终,我想从文件中读取JSON对象,例如像这样的简单对象。{ "happy": true, "pi": 3.141 } 我不太确定如何处理这个问题。在https://github.com/nlohmann上提供了几种从字符串序...

20得票2回答
使用GDB调试/打印自定义类型的C++代码:以nlohmann json库为例

我正在使用nlohmann的json C++实现开展一个项目。 如何在GDB中轻松探索nlohmann的JSON键/值? 我尝试使用STL gdb wrapping,因为它提供了用于探索nlohmann's JSON库使用的标准C++库结构的辅助工具。但我觉得它不太方便。 这里有一个简单...

16得票3回答
C++ nlohmann json - 如何迭代/查找嵌套对象

{"name":"John","age":30,"cars":{"car1":"Ford","car2":"BMW","car3":"Fiat"}} 我试图使用 nlohmann::json 迭代嵌套的 JSON。我的 JSON 对象如下:{ "one": 1, "two":...

15得票3回答
如何在C++中使用nlohmann检查嵌套JSON中是否存在键

我有以下的JSON数据:{ "images": [ { "candidates": [ { "confidence": 0.80836, ...

14得票4回答
如何使用nlohmann::json将JSON对象转换为Map?

例如,使用nlohmann::json,我可以执行map<string, vector<int>> m = { {"a", {1, 2}}, {"b", {2, 3}} }; json j = m; 但我无法做到m = j; 有没...

14得票1回答
使用CMake添加仅包含头文件的依赖项

我有一个简单的项目,需要三个仅包含头文件的库才能编译:websocketpp、spdlog 和 nlohmann/json。项目结构如下:└── src ├── app │   ├── CMakeLists.txt │   ├── src │   └── tes...

13得票1回答
使用nlohmann json将整数列表解包到std::vector<int>中。

我正在使用nlohman::json。 它非常棒,但有没有什么方法可以解包: { "my_list" : [1,2,3] } 如何将其转换为 std:vector&lt;int&gt;? 我在文档中找不到任何提及,std::vector&lt;int&gt; v = j["m...

12得票1回答
如何在nlohmann json中从字符串获取JSON对象?

我有一个字符串,想要将其解析为json格式,但是_json并不总是有效。 #include &lt;nlohmann/json.hpp&gt; #include &lt;iostream&gt; using nlohmann::json; int main() { // Work...

11得票2回答
如何使用“JSON for Modern C++”库检测整数是否适合特定的类型?

这段代码输出-1:#include &lt;iostream&gt; #include &lt;nlohmann/json.hpp&gt; int main() { auto jsonText = "{ \"val\" : 4294967295 }"; auto json =...

9得票1回答
如何在现代C ++中迭代JSON中的内容

我想在一个JSON对象中迭代每个条目,但是我一直遇到难以理解的错误。如何纠正以下示例? #include &lt;iostream&gt; #include &lt;nlohmann/json.hpp&gt; using json = nlohmann::json; void bla(...