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. viewpager的layout_width="wrap_content"无效问题

    在viewpager当中直接使用layout_width="wrap_content"是无效的,扩展了一下.解决这个问题. package com.soulagou.ui; imp ...

  2. TCP/IP笔记 三.运输层(3)——TCP超时重传算法

    TCP 每发送一个报文段,就对这个报文段设置一次计时器.只要计时器设置的重传时间到但还没有收到确认,就要重传这一报文段 1. 平均往返时延RTT 往返时延:一个报文段发出的时间,以及收到相应的确认报文 ...

  3. Github 初识(上传、下载)

    Git - 版本控制工具Github - 一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等GitLab - 基于Git的项目管理软件   上传 1 首先在Github 上注册一 ...

  4. Sicily-1063

    一.题意 一个员工是另外一个员工的老板必须满足的条件是作为老板的员工的薪水salary必须大于这个员工,而且作为老板的员工的身高height要大于等于这个员工.首先按照薪水的多少从小到大进行排序,然后 ...

  5. IOS文件沙盒

    在进行IPhone开发的时候,常常需要将简单的数据保存到文件中,以便下次再重新打开的时候能够读取文件中保存的数据. 下面就来做一个简单的demo: 步骤: 1.创建一个SingleView项目,带有x ...

  6. USB设备在连接PC时的reset从何而来?

    近期在做烧写工具的优化工作,有一些关于USB的内容须要总结一下当中包含设备的初始化过程和枚举过程. 在枚举的过程中,设备会一直等PC端的状态,当等到reset命令时会对设备进行又一次枚举.可是这个re ...

  7. python开发环境安装

    1.首先安装python-3.4.2.msi,此为python主程序,双击安装,根据自身的情况做选择,也可以使用默认设置,一路next也没什么问题. 2.设置环境变量=>编辑Path,在最后加上 ...

  8. TF-IDF算法-自动提取关键词汇

    引子:Automatic Keyphrase extraction 很长文章里面,如何自动提取关键词汇呢? 比如在<中国的蜜蜂养殖>的长文里面,我们准备提取它的关键词.首先一个思路, 那些 ...

  9. 瀑布流的三种实现方式(原生js+jquery+css3)

    前言 项目需求要弄个瀑布流的页面,用的是waterfall这个插件,感觉还是可以的,项目赶就没自己的动手写.最近闲来没事,就自己写个.大致思路理清楚,还是挺好实现的... 原生javascript版 ...

  10. 海量Web日志分析 用Hadoop提取KPI统计指标

    http://blog.fens.me/hadoop-mapreduce-log-kpi/ http://dongxicheng.org/search-engine/scribe-installati ...