nlohmann git地址
https://github.com/nlohmann/json
下载方式
1.git下载
git clone https://github.com/nlohmann/json.git
2.直接下载压缩包
3.cmake + vcpkg下载
vcpkg.json内容
CMakeLists.txt
#指定构建程序需要的最小cmake版本
cmake_minimum_required(VERSION 3.16)
#指定项目的名字及使用的语言
project(TestProject LANGUAGES CXX)
#设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
list(APPEND CMAKE_PREFIX_PATH "./vcpkg_installed/x64-windows")
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# 按目录级别递归遍历,找到所有执行文件
file(GLOB_RECURSE source CONFIGURE_DEPENDS ./*.h ./*.cpp)
add_executable(TestProject ${source})
# 当为FALSE时,运行程序将有CMD窗口。
set_target_properties(TestProject
PROPERTIES
WIN32_EXECUTABLE FALSE
)
#### 批量添加,但要求它们属于同样的PackageName,在这里Qt5是PackageName ####
find_package(Qt5 REQUIRED Widgets Gui Core)
# 添加依赖关系
target_link_libraries(TestProject
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets)
find_package(nlohmann_json REQUIRED)
#target_link_libraries(TestProject nlohmann_json::nlohmann_json)
target_include_directories(TestProject INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_installed/x64-windows/include)
JSON示例
[{
"categoryId": 10,
"categoryName": "Topics",
"langId": 0,
"sortIndex": 100,
"tagList": [{
"defaultStatus": 1,
"sortIndex": 0,
"tagId": 107,
"ta