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. 文件的哈希值不在指定的目录文件中。此文件可能已损坏或被篡(Windows10 /Windows8.1)

    ------------------------------------------Windows10------------------------------------------------ ...

  2. Windows Azure 网站 (WAWS) 中的服务器端包含 (SSI)

     编辑人员注释:本文章由 Windows Azure 网站团队的项目经理Erez Benari 撰写. Windows Azure 网站客户普遍关心的一个问题是关于我们对服务器端包含(Server ...

  3. 犯罪团伙利用POS机刷信用卡积分转卖 年获利千万

      今年1月20日,广东省公安厅展示去年缴获的盗刷专用POS机. 今年1月20日,广东省公安厅展示了一批缴获的盗刷信用卡工具. 他们是一群靠信用卡谋生的年轻人,平均年龄不超过30岁. 他们将各银行信用 ...

  4. Warning: Unable to send packet: Error with PF_PACKET send() [11]: Message too long (errno = 90)

    今天在使用tcpreplay重放流量时,发现有的数据包没有发送成功: Warning: Unable to send packet: Error with PF_PACKET send() [215] ...

  5. 带你走进EJB--MDB

    在之前的文章中我们介绍了带你走进EJB--JMS 和 带你走进EJB--JMS编程模型 对JMS有了初步的了解, 作为EJB系列的文章我们会继续对EJB相关的内容做进一步深的学习和了解.而此次需要进行 ...

  6. POJ1062 昂贵的聘礼 【DFS】

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37475   Accepted: 10816 Descripti ...

  7. poj1201 Intervals【差分约束+SPFA】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

  8. Oracle如何实现跨数据库查询

    转发:http://www.linuxidc.com/Linux/2012-02/53974.htm 实现结果:在一个数据库中某个用户下编写一个存储过程,在存储过程中使用DBLINK连接另一个数据库, ...

  9. CAEmitterLayer 粒子发射器

    在iOS 5中,苹果引入了一个新的CALayer子类叫做CAEmitterLayer.CAEmitterLayer是一个高性能的粒子引擎,被用来创建实时例子动画如:烟雾,火,雨等等这些效果. CAEm ...

  10. struts的常用配置

    struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUB ...