C++ 将字符串数组转换为 JSON 数组
假设三个字符串分别为 'str1'、'str2'、'str3',可以使用以下代码将它们转换成 JSON 数组:
#include <iostream>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main() {
std::string str1 = "Hello";
std::string str2 = "world";
std::string str3 = "!";
std::vector<std::string> strings = { str1, str2, str3 };
json j = strings;
std::cout << j.dump() << std::endl;
return 0;
}
输出结果为:
["Hello","world","!"]
原文地址: https://www.cveoy.top/t/topic/mLoP 著作权归作者所有。请勿转载和采集!