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 ...
随机推荐
- 使用 Windows Media Center 远程控制
http://windows.microsoft.com/en-us/windows/getting-started-windows-media-center#getting-started-wind ...
- 基于Visual C++2013拆解世界五百强面试题--题1-定义各种类型指针
用变量a给出下面的定义 a)一个整型数 b)一个指向整型数的指针 c)一个指向指针的指针,它指向的指针是指向一个整型数 d)一个有10个整型数的数组 e)一个有10个指针 ...
- Libev学习笔记3
设置完需要监听的事件之后,就开始event loop了.在Libev中,该工作由ev_run函数完成.它的大致流程如下: int ev_run (EV_P_ int flags) { do { /* ...
- VC++6.0中各种文件的作用
VC++ 6.0是一款很经典的C/C++开发工具,虽然是1998年的东西了,但是现在使用依然很广!在用它开发的时候,会发现在建立的工程的文件夹里面,有很多文件,各种后缀名.在这里呢,我主要说一下各个文 ...
- leetcode_question_67 Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b ...
- IOS文件沙盒
在进行IPhone开发的时候,常常需要将简单的数据保存到文件中,以便下次再重新打开的时候能够读取文件中保存的数据. 下面就来做一个简单的demo: 步骤: 1.创建一个SingleView项目,带有x ...
- mysqlcluster笔记
1.config的datamemory和indexmemory规定的内存占有量会在ndb启动时直接占用掉,所以在计算内存时,这两个加起来要小于ndb的内存,这两个还只是数据和索引的内存,查询或者插入时 ...
- Mysql的执行顺序
参考:http://blog.csdn.net/jintao_ma/article/details/51253356 http://www.cnblogs.com/rollenholt/p/37769 ...
- CSS的display、hover、overflow、©(版权符号)、borer-radius(边框圆角)
一.display: none 隐藏 block显示 visibility:hidden隐藏 visible显示 display:none和visibility:hidden这两个属性对应的值 ...
- list, tuple, dict, set的用法总结
d = [1, 2, 3, 4, 5, 5] #list print(d) e = ([1, 2], 3, 4, 5555, 5555)#tuple print(e) f = {'Michael':8 ...