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 ...
随机推荐
- zookeeper集群搭建设置
zookeeper 官网:http://zookeeper.apache.org/ 现在最新版本是 3.4.6 ,但是这个版本我没有运行起来,可能是那配置出现问题了,现在我用的是3.4.5 http: ...
- maven 添加自己的包
mvn install:install-file -Dfile=d:/flea.jar -DgroupId=com.flea.bussiness -DartifactId=flea -Dversion ...
- cocos2d基础篇笔记四
1.//有两种集合 //第一种是array 特点:插入,删除效率低,可是查找效率高 //另外一种是list 特点:插入,删除效率高,可是查找效率低 //分析这个游戏: 插入的时候:怪物,射弹出现时, ...
- Java设计模式模式观测(Observer Pattern)
Observer Pattern 设计模式通常用于.这是一个事件侦听器模型. 该模型有两个作用,一个是Subject, 有一个Observer.Subject 保存多个Observer参考,一旦一个特 ...
- Java多线程之非线程安全
在Java多线程中我会重点总结五个如下的技术点: 1.非线程安全是如何出现的 2.synchronized对象监视器为Objec时的使用 3.synchronized对象监视器为Class时的使用 4 ...
- python之列表生成式
列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式. 1,比如:要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, ...
- 字符通向字节流的桥梁---- OutputStreamWriter
OutputStream out = System.out; OutputStreamWriter osw = new OutputStreamWriter(out); BufferedWriter ...
- MongoDB学习笔记1(简介)
一.简介 1.丰富的数据类型 MongoDB是一种非关系型数据库,是面向文档的数据库. MongoDB没有模式,文档的键不会事先定义,也 ...
- B-树和B+树的应用:数据搜索和数据库索引
B-树和B+树的应用:数据搜索和数据库索引 B-树 1 .B-树定义 B-树是一种平衡的多路查找树,它在文件系统中很有用. 定义:一棵m 阶的B-树,或者为空树,或为满足下列特性的m 叉树:⑴树中每 ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...