C :在项目中使用Nlohmann JSON
C++ : using nlohmann json in project
我试图在我的C 项目中使用Nlohmann JSON。从Github下载后,我提取了拉链文件。我将提取的文件夹重命名为nlohmann_json
,然后将其复制在我的项目中。
github doc说:
json.hpp是Single_include/nlohmann中所需的单个文件或在此处发布。您需要添加
#include <nlohmann/json.hpp>
// for convenience
using json = nlohmann::json;
所以在我的 .cpp
文件中,我有以下行:
#include "nlohmann_json/include/nlohmann/json.hpp"
using json = nlohmann::json;
但是Visual Studio 2015 IDE作为工具提示以下消息显示:
名称空间Nlohmann没有成员JSON
仅键入nlohmann::
后,我得到了json_pointer
的自动建议,但没有json
。
实际上怎么了?
您实际上对您的问题有提示。
json.hpp is the single required file in single_include/nlohmann or released here. You need to add
如果您转到从Github检查的原始树,然后执行此操作:
$ find . -name json.hpp
./include/nlohmann/json.hpp
./single_include/nlohmann/json.hpp
您可能会看到您的问题。您包括第一个找到的文件。您确实需要第二个或 - 需要设置的第二个,包括搜索路径更好。
这就是我要做的。我会复制./single_include/nlohmann/json.hpp中。我不会包括整棵树,只是该文件。并包括它。
我认为这对您有利。
您可以使用单个标头方法,可以在其中直接包含一个json.hpp(在单个_include中,只需将nlohmann/json.hpp放在项目的根部(即可。或者,如果要包含一个具有多个文件的文件,则需要在VS项目设置中设置其他包含标题。
MyProj
nlohmann....
main.cpp
然后,在您的VS项目设置中,将项目的路径添加到附加目录。
相关文章:
- nlohmann-json将一个数组插入到另一个数组中
- JSON转换为nlohmann JSON-lib中的结构数组
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- 为什么 nlohmann/json 序列化 "null" 而不是在 double 上"0"?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- nlohmann/json uWebsocket
- std::string 可以作为 nlohmann::json 传递给显式构造函数
- 使用 NLOHMANN JSON 在 C++ 中创建嵌套的 JSON 对象
- 如何使用 nlohmann/json.hpp 序列化 2 个集合
- C++ nlohmann JSON 获取数组名称
- Json Serialize Vector to json<Class> array (nlohmann/json.hpp)
- 使用Nlohmann JSON将JSON数据保存在文件中时获取空值
- C :在项目中使用Nlohmann JSON
- JSON使用Nlohmann Json进行解析
- 如何从 nlohmann json 获取对象条目
- nlohmann JSON:序列化像 int* 这样的数组
- 使用 nlohmann json 将整数列表解压缩为 std::vector<int>
- nlohmann JSON,更改键的值
- C 返回函数的函数返回JSON数组通过Nlohmann Json.hpp