c++ - Create empty json array with jsoncpp - Stack Overflow
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c++ - Create empty json array with jsoncpp - Stack Overflow,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2342字,纯文字阅读大概需要4分钟。
内容图文
![c++ - Create empty json array with jsoncpp - Stack Overflow](/upload/InfoBanner/zyjiaocheng/1177/b40f10406c59450e91aa005a75d34e3e.jpg)
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"=[]}
原文:http://www.cnblogs.com/lexus/p/3531767.html
内容总结
以上是互联网集市为您收集整理的c++ - Create empty json array with jsoncpp - Stack Overflow全部内容,希望文章能够帮你解决c++ - Create empty json array with jsoncpp - Stack Overflow所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。