cgi+json

本文示例展示了如何使用Boost库解析和生成JSON数据,同时讲解了CGI程序如何通过环境变量获取客户端数据。代码中包含了JSON字符串的读取、点集数据的构造和序列化为JSON格式,以及CGI接口中QUERY_STRING的处理。
摘要由CSDN通过智能技术生成
 
#define  _CRT_SECURE_NO_WARNINGS
#include <boost/property_tree/ptree.hpp>  
#include <boost/property_tree/json_parser.hpp>  
#include <boost/foreach.hpp> 
#include<opencv2/opencv.hpp> 
#include<vector>
#include <sstream>

using namespace std;
using namespace cv;
using namespace boost::property_tree;



int main() {
	
	string str_json = "{\"ret\":\"http://ovuhjq3qc.bkt.clouddn.com/2017-11-1617:20:22-920-.png\",\"error\":\"errortype\"}";
	ptree pt;                       //define property_tree object
	stringstream ss(str_json);        //字符串流stringstream,把string类型转换为stringstream
	try {
		read_json(ss, pt);          //reson_json函数将文件流、字符串解析到ptree
	}
	catch (ptree_error & e) {
		return 1;
	}
	string str = pt.get<std::string>("ret");     //获取到json数据的key的值value
	cout << str << endl;
	st
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值