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的更多相关文章

  1. Poco::JSON::Array 中object 设置preserveInsertionOrder 时,stringify出错-->深入解析

    在使用poco version 1.6.0时 Poco::JSON::Array 在object  设置preserveInsertionOrder =true 时 调用 array.stringif ...

  2. 解决: Fail to create empty document

    做 Programming Windows with MFC 2nd 的例子 MyWord 的时候. 发现启动的时候总是报错: Fail to create empty document. 搜索了一下 ...

  3. 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 ...

  4. 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 ...

  5. 从零开始——JSON ARRAY&JSON OBJECT

    在学习“基于角色的权限”的例子中,遇到了json object和json array,因此在一番学习之后对此要点进行粗略整理. 参考: https://my.oschina.net/u/2601842 ...

  6. [Cannot deserialize JSON array into type] NewtonSoft.Json解析数据出错原因

    今天用NewtonSoft.JSon解析一个天气数据,数据格式如: {"status":1,"detail":"\u6570\u636e\u83b7\ ...

  7. Stack Overflow 上排名前十的与API相关的问题

    Stack Overflow是一个庞大的编程知识仓库,在Stack Overflow 上,数百万的提问被回答,并且这些回答都是高质量的.这就是为什么在Google搜索结果的排行榜上,Stack Ove ...

  8. Stack Overflow: The Architecture - 2016 Edition(Translation)

    原文: https://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/ 作者:Nick Cra ...

  9. 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 ...

随机推荐

  1. 在TreeWidget中增加右键菜单功能 以及TreeWidget的基本用法

    TreeWidget 与 TreeView 中实现右键菜单稍有不同, TreeView 中是靠信号与槽 connect(ui->treeView,SIGNAL(customContextMenu ...

  2. Docker学习总结之Run命令介绍

    Docker学习总结之Run命令介绍 本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 在使用Docker时,执行最多的命令某 ...

  3. web应用中Spring ApplicationContext的动态更新

    在web应用中时常需要修改配置,并动态的重新加载ApplicationContext.比如,设置和切换数据库.以下给出一个方法,并通过代码验证可行性. 方法的基本思路是,为WebApplication ...

  4. AlertDialog弹出时背景明暗程度调整

    今天有个需求是把弹出AlertDialog时的变暗的背景调整得不要那么暗. 一开始懒惰就直接百度中文搜索,结果找到的代码试了几次都不行. 后来老老实实开google.stackoverflow搜索,搜 ...

  5. SharePoint 2010 用Event Receiver将文件夹自动变成approved状态 (1)

    当开发一个sharepoint门户网站,或者是一个内容管理的网站的时候,站点的模板通常会选用publish portal,或者是开启了publishing feature来对内容进行版本控制和流程控制 ...

  6. citrix协议ICA技术原理

    转载自: http://www.zrss.com.cn/article-110-1.html Citrix交付中心解决方式的核心是虚拟化技术,虚拟化计算的核心是ICA协议,ICA协议连接了执行在平台上 ...

  7. 【科研论文】基于文件解析的飞行器模拟系统软件设计(应用W5300)

    摘要: 飞行器模拟系统是复杂飞行器研制和使用过程中的重要设备,它可以用来模拟真实飞行器的输入输出接口,产生与真实系统一致的模拟数据,从而有效避免因使用真实飞行器带来的高风险,极大提高地面测发控系统的研 ...

  8. GCC编译四阶段

    Linux下程序编译的四个阶段:预处理.编译.汇编.链接 GCC: GUN  C Compiler 但现在不只局限于c语言 预处理(Preprocessing): gcc  -E  hello.c - ...

  9. Extending your SharePoint 2007 site with Microsoft ASP.NET AJAX 3.5

    After ASP.NET 3.5 has been installed you need to modify the web.config file of your MOSS web site wi ...

  10. c#中使用log4net工具记录日志

    首先,去官网下载log4net工具 链接http://logging.apache.org/log4net/download_log4net.cgi 目前最新的版本 log4net-1.2.15-bi ...