vs c++ qt 叫请求的json 输出到输出终端

1 接收数据

std::string response = "";

//设置数据接收函数

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Utils::req_reply);

// 设置写入数据的缓冲区

curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&response);

2 打印 数据类型

qDebug() << "data:" << typeid(response).name();

3 打印指定数据

// 使用 nlohmann/json 命名空间

#include <nlohmann/json.hpp>

using json = nlohmann::json;

try {

json j = json::parse(data);

// 使用 qDebug() 输出 JSON 字符串

qDebug().noquote() << QString::fromStdString(j.dump()); //std::string jsonString = j.dump();

// 提取字段

std::string code = j"code";

std::string msg = j"msg";

json data = j"data";

}

catch (json::parse_error& e) {

std::cerr << "JSON parse error: " << e.what() << '\n';

}

相关推荐
众少成多积小致巨14 小时前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
疯狂SQL21 小时前
手写高性能在线 JSON 工具|Web Worker 工程化打包 + 语法自动修复 + 多语言代码生成实战
typescript·json·next.js·web worker·前端性能优化·esbuild·源码实战
clint4565 天前
C++进阶(1)——前景提要
c++
夜悊5 天前
C++代码示例:进制数简单生成工具
c++
郝学胜_神的一滴5 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0015 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
LDR0066 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术6 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园6 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob6 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio