栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【无标题】c++读取json文件

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】c++读取json文件

json文件示例:
{“http”:[{

	"1":{
	   "fun_id" : 1,
	   "run_begin_time" : "2022-07-08-15-24-01"
       	},
	
	"2":{
	   "data" : {
	      "0" : 75.77000000000001,
	      "1" : 54.830000000000013,
	      "2" : 58.180000000000007,
	      "3" : 66.030000000000001,
	      "4" : 56.140000000000001,
	      "5" : 64.310000000000002,
	      "6" : 67.730000000000004,
	      "7" : 55.400000000000006,
	      "8" : 60.540000000000006,
	      "9" : 55.850000000000001
	               }
	        },
	        
	"3":{
	   "resultID" : 0,
	   "run_end_time" : "2022-07-08-15-24-04"
	      }

}]
}

c++代码:

//读取json文件

#include “stdafx.h”
#include
#include
#include
#include
//#include
using namespace std;

void readJson();

int main1()
{
readJson();
system(“pause”);
return 0;
}

void readJson()
{
Json::Reader reader;
Json::Value root;
string jsonPath = “E:Point_EV_Spatialres_httpServerjsoncloud_tower_all-2022-07-08-15-24-00.json”;
ifstream is(jsonPath, ios::binary);

if (!is.is_open())
{
	cout << "Error opening" << endl;
	return;
}

	reader.parse(is, root);

	Json::StyledWriter sw;
	cout << sw.write(root);

	int j = root["http"].size();
	cout << root["http"][j - 1]["2"]["data"]["1"].asString();

	int resultID = root["resultID"].asInt();
   
	if (root["s"].type()==Json::nullValue)    //判断json中是否存在s节点
    {
		cout << "不存在的节点"< 

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1011814.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号