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. HDU 2852 KiKi's K-Number

    权值线段树 #include <cstdio> #include <cstring> const int N=200000,M=220000; int k,q,x,y,sum[ ...

  2. 未能加载文件或程序集“DAL”或其他的某一个依赖项,系统找不到指定的文件

    针对这个问题我在敲VB.NET机房收费系统的时候总共出现了两次,第一次是在使用反射+抽象工厂的时候出现的,第二次是在使用VS2012自带的打包工具生成可执行文件执行exe文件的时候出现的.具体看下图: ...

  3. EGL接口 简单介绍

    from http://lyodev.appspot.com 第二章 EGL 接口 EGL 是 OpenGL ES 和底层 Native 平台视窗系统之间的接口.本章主要讲述 OpenGL ES 的 ...

  4. java--折半查找

    /* 折半查找 */ class TwoSearch { //折半查找可以提高效率,但必须得保证是有序的数组 public static int halfSearch(int[] arr,int ke ...

  5. SqlBulkCopy的使用

    1.问题:导入大数据量到数据库,用我们普通的SqlHelper来做是每插入一条都是打开连接关闭连接,这样太慢,因此我们会想到让SqlConnection一直打开直到所有数据都插入完成再关闭连接.但是根 ...

  6. 常用类库StringBuilder

    1.使用StringBuilder拼接字符串实例: string[] lines = File.ReadAllLines("sdjk.txt", Encoding.Default) ...

  7. 【转载】国内网站博客数据统计选免费Google Analytics还是百度统计

    [转载]国内网站博客数据统计选免费Google Analytics还是百度统计 Google Analytics谷歌统计是我用的第一个网站统计工具,当然现在也一直在用.Google Analytics ...

  8. CSS3-旋转齿轮

    CSS3-旋转齿轮 查看DEMO 通过 CSS3,我们能够创建动画,这可以在许多网页中取代动画图片.Flash 动画以及 JavaScript. 先来认识一下css3的animation animat ...

  9. Sed简介 (转)

    Sed简介 sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓 ...

  10. python成长之路16

    阅读(72) 一:jQuery是一个兼容多浏览器的javascript类库,核心理念是write less,do more(写得更少,做得更多),对javascript进行了封装,是的更加便捷的开发, ...