使用C++将三个string转换为json array
假设三个string分别为str1、str2、str3,可以使用以下代码将它们转换成json array:
#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","!"]
原文地址: http://www.cveoy.top/t/topic/bjjH 著作权归作者所有。请勿转载和采集!