JSON函数表
jsoncpp 主要包含三个class:Value、Reader、Writer。注意Json::Value 只能处理 ANSI 类型的字符串,如果 C++ 程序是用 Unicode 编码的,最好加一个 Adapt 类来适配。
Json内部类和方法:
Reader<是用于读取的,说的确切点,是用于将字符串转换为 Json::Value 对象的>
【构造函数】
1、Reader();
【拷贝构造函数】
2、Reader( const Features &features );
【将字符串或者输入流转换为JSON的Value对象】
【下边是相应的parse的重载函数】
3、bool parse( const std::string &document, Value &root,bool collectComments = true );
4、bool parse( const char *beginDoc, const char *endDoc,
Value &root,bool collectComments = true
5、bool parse( std::istream &is,Value &root,bool collectComments = true );
6、std::string getFormatedErrorMessages() const;
Value:<是jsoncpp 中最基本、最重要的类,用于表示各种类型的对象,jsoncpp 支持的对象类型可见 Json::ValueType 枚举值; Value类的对象代表一个JSON值,既可以代表一个文档,也可以代表 文档中一个值。如同JSON中定义的“值”一样,Value是递归的>
【构造函数】
1、Value( ValueType type = nullValue );
Value( Int value );
Value( UInt value );
Value( double value );
Value( const char *value );
Value( const char *beginValue, const char *endValue );
【拷贝构造函数】
2、Value( const StaticString &value );
Value( const std::string &value );
Value( const Value &other );
【相同类型的比较、交换、类型的获取】
3、void swap( Value &other );
ValueType type() const;
int compare( const Value &other );
【相应的赋值运算符的重载函数】
4、Value &operator=( const Value &other );
bool operator <( const Value &other ) const;
bool operator <=( const Value &other ) const;
bool operator >=( const Value &other ) const;
bool operator >( const Value &other ) const;
bool operator ==( const Value &other ) const;
bool operator !=( const Value &other ) const;
bool operator!() const;
Value &operator[]( UInt index );
const Value &operator[]( UInt index ) const;
【将Value对象进行相应的类型转换】
5、const char *asCString() const;
std::string asString() const;
const char *asCString() const;
std::string asString() const;
Int asInt() const;
UInt asUInt() const;
double asDouble() const;
【相应的判断函数】
6、bool isNull() const;
bool isBool() const;
bool isInt() const;
bool isUInt() const;
bool isIntegral() const;
bool isDouble() const;
bool isNumeric() const;
bool isString() const;
bool isArray() const;
bool isObject() const;
bool isConvertibleTo( ValueType other ) const;
bool isValidIndex( UInt index ) const;
bool isMember( const char *key ) const;
bool isMember( const std::string &key ) const;
【清除和扩容函数】
7、void clear();
void resize( UInt size );
【获取满足相应条件的Value】
8、Value get( UInt index, const Value &defaultValue ) const;
Value get( const std::string &key,const Value &defaultValue ) const;
Members getMemberNames() const;
【删除满足相应条件的Value】
9、Value removeMember( const char* key );
Value removeMember( const std::string &key );
10、void setComment( const char *comment,CommentPlacement placement );
void setComment( const std::string &comment,CommentPlacement placement );
bool hasComment( CommentPlacement placement ) const;
std::string getComment( CommentPlacement placement ) const;
std::string toStyledString()const;
Writer:<类是一个纯虚类,并不能直接使用。在此我们使用 Json::Writer 的子类(派生类):
Json::FastWriter、Json::StyledWriter、Json::StyledStreamWriter。顾名思义,用 Json::FastWriter 来处理 json 应该是最快的;负责将内存中的Value对象转换成JSON文档,
输出到文件或者是字符串中>
【FastWriter】
1、FastWriter();
virtual ~FastWriter(){}
void enableYAMLCompatibility();
virtual std::string write( const Value &root );
【StyledWriter】
2、StyledWriter();
virtual ~StyledWriter(){}
virtual std::string write( const Value &root );
JSON函数表的更多相关文章
- JSON函数表2
[class] Json::Reader [public] [将字符串或者输入流转换为JSON的Value对象] bool parse( const std::string &document ...
- JSON函数表1
jsoncpp 主要包含三个class:Value.Reader.Writer.注意Json::Value 只能处理 ANSI 类型的字符串,如果 C++ 程序是用 Unicode 编码的,最好加一个 ...
- C++ 虚函数表解析
转载:陈皓 http://blog.csdn.net/haoel 前言 C++中 的虚函数的作用主要是实现了多态的机制.关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实 ...
- C++ 多态、虚函数机制以及虚函数表
1.非virtual函数,调用规则取决于对象的显式类型.例如 A* a = new B(); a->display(); 调用的就是A类中定义的display().和对象本体是B无关系. 2. ...
- C++迟后联编和虚函数表
先看一个题目: class Base { public: virtual void Show(int x) { cout << "In Base class, int x = & ...
- C++ 知道虚函数表的存在
今天翻看陈皓大大的博客,直接找关于C++的东东,看到了虚函数表的内容,找一些能看得懂的地方记下笔记. 0 引子 类中存在虚函数,就会存在虚函数表,在vs2015的实现中,它存在于类的头部. 假设有如下 ...
- C++虚函数和虚函数表
前导 在上面的博文中描述了基类中存在虚函数时,基类和派生类中虚函数表的结构. 在派生类也定义了虚函数时,函数表又是怎样的结构呢? 先看下面的示例代码: #include <iostream> ...
- C++ Daily 《5》----虚函数表的共享问题
问题: 包含一个以上虚函数的 class B, 它所定义的 对象是否共用一个虚函数表? 分析: 由于含有虚函数,因此对象内存包含了一个指向虚函数表的指针,但是这个指针指向的是同一个虚函数表吗? 实验如 ...
- C++虚函数表
大家知道虚函数是通过一张虚函数表来实现的.在这个表中,主要是一个类的虚函数的地址表,这张表解决了继承.覆盖的问题,其内容真是反应实际的函数.这样,在有虚函数的类的实例中,这个表分配在了这个实例的内存中 ...
随机推荐
- JS基础_数组的遍历
遍历:将数组中所有的元素都取出来 1.for循环 var arr = ["1","2","3"]; for(let i=0;i<arr ...
- 【转载】Python tips: 什么是*args和**kwargs?
转自Python tips: 什么是*args和**kwargs? 先来看个例子: def foo(*args, **kwargs): print 'args = ', args print 'kwa ...
- 刘汝佳dicnic模板
#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #in ...
- CSS 优先级法则
样式的优先级 多重样式(Multiple Styles):如果外部样式.内部样式和内联样式同时应用于同一个元素,就是使多重样式的情况. 一般情况下,优先级如下: (外部样式)External styl ...
- [go]包管理
vendor方式 //包管理发展 go get(无版本概念) -> vendor(godep)(无版本概念) -> go modules go get github.com/tools/g ...
- RabbitMQ学习之:(七)Fanout Exchange (转贴+我的评论)
From:http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/ PunCha: Ther ...
- [git]使用Idea创建一个git项目
第一次使用git的方法,如建立的项目名叫:my-webapp 第一步:在远程gitlab上建立空白项目:my-webapp 第二步:在本地建立项目my-webapp,添加代码 第三步:创建一个本地 ...
- 2018网特招新题writeup
沈永宁(周鸣振)这狗比,晚上才发现他隐姓埋名偷偷刷了分还刷到了第一名,不行我也刷...我刷刷刷
- SQL语句之数据定义语言(DDL)详解
操作对象:数据库 1)创建数据库 MariaDB [(none)]> help create databaseName: 'CREATE DATABASE'Description:Syntax: ...
- CentOS7或CentOS8 安装VirtualBox Guest Addon缺少kernel-headers的解决办法
CentOS7或CentOS8 在Oracle VM VirtualBox中安装Guest Addon时,如果缺少kernel-headers和相应的编译库,会提示出错. "kernel h ...