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. vs c++ qt 请求json 输出输出终端

    2024-01-06 16:40:04       46 阅读
  2. Shell 输入输出:从 Read 管道奇妙旅程

    2024-01-06 16:40:04       35 阅读
  3. 数据输入输出(C++)

    2024-01-06 16:40:04       59 阅读
  4. C++ 基本输入输出

    2024-01-06 16:40:04       63 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-06 16:40:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-06 16:40:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-06 16:40:04       87 阅读
  4. Python语言-面向对象

    2024-01-06 16:40:04       96 阅读

热门阅读

  1. 优医问诊H5 Vue3+TS+Pinia+Vant源码。

    2024-01-06 16:40:04       46 阅读
  2. 缓冲和缓存的区别

    2024-01-06 16:40:04       58 阅读
  3. 数据结构-怀化学院期末题(489)

    2024-01-06 16:40:04       54 阅读
  4. 【Python_PySide学习笔记(目录)】

    2024-01-06 16:40:04       55 阅读
  5. 数据结构 第三章节 栈和队列

    2024-01-06 16:40:04       47 阅读