使用下面的代码,我们可以从JSON文件的第一个节点访问第一个数据,但是我们希望读取JSON文件下面的所有值。请提供您对这一问题的投入。
boost::property_tree::ptree TreeNode;TreeNode根;TreeNode根);if(root.size()<=0) { LOGMSG<<"JSON_File为空。\n“;返回bReturn;}命名空间pt = boost::property_tree;我只想阅读json文件下面的“Datavalue: 0,7”:[{ "id":1,"orderNum":1,“标题”:“主要社会经济指标”,“副标题”:null,"isVisible":true,"regionId":741880,“数据”:[{ "id":629147,"orderNum":1,“标题”:“人口”,“副标题”:"(1.12.2019,千人)“,"dataValue":”18611,1“,“图标”:"naselenie.png","isVisible":true },{ "id":629148,"orderNum":2,“orderNum”:"GDP ",“isVisible”:“(2019年1-9月,%)","dataValue":"104,3",“图标”:"vvp.png","isVisible":true },{ "id":629149,"orderNum":3,“标题”:“通货膨胀",“副标题”:“(2019年12月至2018年12月,%)","dataValue":"5,4",”图标“:"inflation.png","isVisible":true },{ "id":629150,"orderNum":4,“标题”:“通货膨胀",”副标题“:”(2019年12月至2019年11月,%)","dataValue":"0,7",“图标”:"inflation.png","isVisible":true },{ "id":6291,"orderNum":5,“标题”:“失业率”,“副标题”:“(2019年12月,%,估计数据)”,"dataValue":"4,8",“图标”:"bezrabotica.png","isVisible":true },c++
发布于 2020-01-28 05:45:57
我的建议是:不要。
标准库有很容易做到这一点的工具。老学生可能只会使用sscanf。
char input[] = "27/01/2020";
int day, month, year;
sscanf(input, "%d/%d/%d", &day, &month, &year);如果您喜欢流,您可能更喜欢get_time操作器:
std::stringstream input("27/01/2020");
tm date;
input >> std::gettime(&date, "%d/%m/%Y");然后...and date.tm_mday将包含27,date.tm_month将包含01,date.tm_year将包含120 (即1900年)。
如果您真的想(或需要)使用iGlib::Trim,您可能需要查阅该库的文档--它似乎并不是众所周知的(这也是我建议避免使用它的原因之一)。
发布于 2020-01-28 05:31:25
使用split(date, '/')。
std::vector<std::string> split(const std::string& s, char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}取自这里
https://stackoverflow.com/questions/59942476
复制相似问题