bson的操作
2015-08-17 15:17
176 查看
bson的操作
flyfish 2015-8-27
使用的是bson-cpp
bson的创建
bson的输出
flyfish 2015-8-27
使用的是bson-cpp
bson的创建
//{ name : 'joe', age : 33.7 } //方式1 bson::bo a = bson::bob().append("name", "joe").append("age", 33.7).obj(); //方式2 bson::bob x; x.append("name", "joe"); x.append("age", 33.7); bson::bo b=x.obj(); //方式3 bson::bo c = BSON("name"<< "joe" <<"age"<<33.7); //嵌套方式 bson::bo d = BSON( "x" << "1" << "y" << true << "subobj" << BSON( "m" << 3 << "n" << 4 ) );
bson的输出
//输出方式1 c["name"] c["age"] //输出方式2 for( bson::bo::iterator it(c); it.more(); ) { string s=it.next().toString(); } //输出方式3 for(bson::bo::iterator it=c.begin(); it.more();) { bson::be t=it.next(); string s=t.fieldName();// 输出的是 age,name if(t.type() == bson::String) { t.valuestr();//输出 joe } else if (t.type() == bson::NumberDouble) { t._numberDouble();//输出 33.7 } }
相关文章推荐
- poj 1836 Alignment
- JavaSE 面向对象内存图&静态变量内存图
- EventBus, otto, LocalBroadcast的选择
- 裴波那数列的计算
- chattr和lsattr命令
- 【算法之旅】——-算法初识
- 解决Android Webview 加载一些网页出现白板现象
- windows下安装gevent
- Eclipse代码整体后退或前移
- LINUX使用FTP搭建网络版YUM源
- Java 获取距离最近一段时间的时间点
- MFC中定时器的使用
- XML 特殊字符处理
- C# String与string的区别 以及 C# Swap string
- (7) <IED> eclipse-3.6.1-64安装反编译插件 JD_Eclipse插件
- Java初级培训笔记------容器 (3)
- mac 刻录ISO系统盘
- Android使用surface直接显示yuv数据(三)
- 散户炒股为何一买就跌 一卖就涨?
- Jersey服务开启却报404的错误