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 天前
算法竞赛C++常用的STL
c++·算法
weilx12341 天前
C++笔记-文件IO-<fcntl.h>
c++
小羊没烦恼!1 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
譕痕1 天前
JSONObject与JSONArray封装数据格式区别
java·json
A黄俊辉A1 天前
uniapp webview中实现 app和内嵌的H5双向通信
vue.js·json
伞伞悦读1 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
Smileyqp沛沛1 天前
前端?C++ ?较大差异基础罗列
c++·基础·前端转c++
C语言小火车1 天前
C/C++ 为什么需要编译器?
开发语言·c++
旖旎夜光1 天前
力控面试题 01.01: 判定字符是否唯一(位运算) —— 题解
c++·学习·算法·leetcode·力控
吞下星星的少年·-·1 天前
C++ 萌新语法入门篇
c++·算法比赛