c++ - Create empty json array with jsoncpp - Stack Overflow
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客
multiprocessing.pool
c++ - Create empty json array with jsoncpp - Stack Overflow
Create empty json array with jsoncpp
up vote 1 down vote favorite
1
I have following code:
voidMyClass::myMethod(Json::Value& jsonValue_ref){for(int i =0; i <= m_stringList.size(); i++){if(m_boolMarkerList[i]){
jsonValue_ref.append(stringList[i]);}}}voidMyClass::myOuterMethod(){Json::Value jsonRoot;Json::Value jsonValue;
myMethod(jsonValue);
jsonRoot["somevalue"]= jsonValue;Json::StyledWriter writer;
std::string out_string = writer.write(jsonRoot);}
If all boolMarkers are false the out_string is { "somevalue" : null } but I want it to be an empty array: { "somevalue" : [ ] }
Does anybody know how to achieve this?
Thank you very much!
c++ json jsoncpp
share|edit|flag
asked Nov 8 '12 at 16:17
Martin Meeser
190110
add comment
start a bounty
3 Answers
active oldest votes
up vote 5 down vote accepted
You can do it also this way:
jsonRootValue["emptyArray"]=Json::Value(Json::arrayValue);
share|edit|flag
answered Feb 28 '13 at 13:36
user609441
6613
add comment
up vote 1 down vote
You can do this by defining the Value object as an "Array object" (by default it makes it as an "object" object which is why your member becomes "null" when no assignment made, instead of [] )
So, switch this line:
Json::Value jsonValue;
myMethod(jsonValue);
with this:
Json::Value jsonValue(Json::arrayValue);
myMethod(jsonValue);
And voila! Note that you can change "arrayValue" to any type you want (object, string, array, int etc.) to make an object of that type. As I said before, the default one is "object".
share|edit|flag
answered Mar 4 '13 at 9:28
Ahmet Ipkin
528
upvote
flag
Thank you Ahmet but this is exactly the same as user609441 already stated with a little more text. – Martin Meeser Mar 5 '13 at 11:18
upvote
flag
Wanted to explain the reasons as well ^_^ – Ahmet Ipkin Mar 7 '13 at 7:29
add comment
up vote 0 down vote
OK I got it. It is a little bit annoying but it is quite easy after all. To create an empty json array with jsoncpp:
Json::Value jsonArray;
jsonArray.append(Json::Value::null);
jsonArray.clear();
jsonRootValue["emptyArray"]= jsonArray;
Output via writer will be:
{"emptyArray"=[]}
c++ - Create empty json array with jsoncpp - Stack Overflow的更多相关文章
- Poco::JSON::Array 中object 设置preserveInsertionOrder 时,stringify出错-->深入解析
在使用poco version 1.6.0时 Poco::JSON::Array 在object 设置preserveInsertionOrder =true 时 调用 array.stringif ...
- 解决: Fail to create empty document
做 Programming Windows with MFC 2nd 的例子 MyWord 的时候. 发现启动的时候总是报错: Fail to create empty document. 搜索了一下 ...
- Python load json file with UTF-8 BOM header - Stack Overflow
Python load json file with UTF-8 BOM header - Stack Overflow 3 down vote Since json.load(stream) use ...
- javascript - C++, Qt, QtWebKit: How to create an html rendering window so that your application would get callbacks from JS calls? - Stack Overflow
javascript - C++, Qt, QtWebKit: How to create an html rendering window so that your application woul ...
- 从零开始——JSON ARRAY&JSON OBJECT
在学习“基于角色的权限”的例子中,遇到了json object和json array,因此在一番学习之后对此要点进行粗略整理. 参考: https://my.oschina.net/u/2601842 ...
- [Cannot deserialize JSON array into type] NewtonSoft.Json解析数据出错原因
今天用NewtonSoft.JSon解析一个天气数据,数据格式如: {"status":1,"detail":"\u6570\u636e\u83b7\ ...
- Stack Overflow 上排名前十的与API相关的问题
Stack Overflow是一个庞大的编程知识仓库,在Stack Overflow 上,数百万的提问被回答,并且这些回答都是高质量的.这就是为什么在Google搜索结果的排行榜上,Stack Ove ...
- Stack Overflow: The Architecture - 2016 Edition(Translation)
原文: https://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/ 作者:Nick Cra ...
- Stack Overflow: The Architecture - 2016 Edition
To get an idea of what all of this stuff “does,” let me start off with an update on the average day ...
随机推荐
- nodejs--express开发个人博客(2)
上一部分已经实现了视图的雏形,现在加上逻辑操作. 登陆.注册.文章发表都需要用到数据库的数据存取,用的比较多的就是mongodb了. MongoDB 是一个对象数据库,它没有表.行等概念,也没有固定的 ...
- cocos2d-x中的尺寸之二
接下来我们再做些坏事,比如给EGLView设置分辨率,代码如下: pEGLView->setDesignResolutionSize(240, 320, kResolutionExactFit) ...
- HDU 2962 Trucking
题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...
- hdoj 3065 病毒侵袭持续中(AC自动机)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 思路分析:问题需要模式匹配多个模式串,需要注意的是模式串会包含和重叠,需要对AC自动机的匹配过 ...
- iOS开展-CocoaPods安装和使用教程
原文链接: iOS开展-CocoaPods安装和使用教程 修正已经增加了自己的理解. CocoaPods安装和使用教程 Code4App 原创文章.转载请注明出处:http://code4app.co ...
- 2014多校3 Wow! Such Sequence!段树
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4893 这个问题还真是纠结啊--好久不写线段树的题了.由于这几天学伸展树.然后认为线段树小case了. ...
- 安卓入门学习之Hello,world!
第二章 Hello,world! 本文同时发表至简书,不为什么,用他的MarkDown在线编辑爽得要哭. 注意:本章节所使用的开发工具为Eclipse 以Android编程权威指南作为学习书物 第一节 ...
- for语句的嵌套(示例及练习)
for(初始条件:循环条件:状态改变) {for(初始条件:循环条件:状态改变) { 循环体 }} 一般,用来解决循环的方法:穷举法.迭代法. 示例一:阶乘的和 示例二: 练习一:兔 ...
- 关于RMAN的配置信息存储和控制文件的关系
没有使用catalog时,rman中的所有配置信息都会记入在 控制文件中 控制文件中dump出来的信息: *********************************************** ...
- jquery 中多个存在依赖关系的ajax调用解决办法
在使用ajax异步调用的时候,可能碰到同时调用多个ajax这种情况.而且多个ajax之间还存在依赖关系.这种情况怎么处理呢? 有两种办法: 一种是多个ajax嵌套调用,这时需要设置async为fa ...