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 ...
随机推荐
- hdu2964-Prime Bases
http://acm.hdu.edu.cn/showproblem.php?pid=2964 题意,给你一个整数n,现在要你分解成 n = k1 * ( 2 * 3 * ....*x1 ) + k2 ...
- poj2492 A Bug's Life【基础种类并查集】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298148.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
- Leetcode解题记录
尽量抽空刷LeetCode,持续更新 刷题记录在github上面,https://github.com/Zering/LeetCode 2016-09-05 300. Longest Increasi ...
- javascript事件及事件传输
函数必须调用才能执行,可a()加下面的函数调用 JS事件 1.js事件通常和函数结合来使用,这样可以通过发生的事件来驱动函数的执行,从而引起html出现不同的效果. 2.属性(当这些事件的属性发生时, ...
- 简简单单C#爬虫小计
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- 使用OFFSET-FETCH进行数据过滤
TOP的工业标准版 OFFSET-FETCH OFFSET 用来设置跳过行的数量 FETCH 用来设置检索多少行,必须要排序才能用,SQL Server 2012的新语法 从语意的角度来讲如果要跳开几 ...
- IOS开发之格式化日期时间的使用 && 编程中常见问题
今天在做一个有关时间的一些开发的时候,遇见了一写问题,反正来说既是很简单的问题,但毕竟用了我一些时间去调错误,遂记录之. 本来是想用 NSDateFormat 来转换一下服务器返回的时间,然后在客户端 ...
- C# Best Practices - Handling Strings
Features Strings Are Immutable. A String Is a Reference Type Value Type Store their data directly Ex ...
- OD调试篇1—Hello
OD调试篇1—Hello 要求:通过OD将程序的标题“I love fishc.com”改为“I love you” 一.找到程序的标题“I love fishc.com” 1.把程序拖到OD运行出现 ...
- cocos2dx进阶学习之CCDirector
继承关系 CCDirecotor -> CCObject, TypeInfo 处理主窗口消息,管理何时.何种方式执行场景. 经常被翻译成导演,负责管理整个游戏的进程推动和周边支持. 成员 inl ...