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';

}

相关推荐
不想写代码的星星1 小时前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus2 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit4 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_5 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星5 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛7 天前
delete又未完全delete
c++
端平入洛8 天前
auto有时不auto
c++
郑州光合科技余经理9 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1239 天前
matlab画图工具
开发语言·matlab
dustcell.9 天前
haproxy七层代理
java·开发语言·前端