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. Protel99se教程七:创建PCB元件封装

    在上一节课当中,我们给大家讲解了如何制作SCH原理图的元件库,这一节课,我们给大家讲解的是如何制作protel99se封装,在我们制作好元件好,需要制作对应的封装库,以供PCB设计所用. 第一步:进入 ...

  2. ListBox控件例子

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListBox.aspx.c ...

  3. C#获取桌面壁纸图片的路径(Desktop Wallpaper)

    原文 C#获取桌面壁纸图片的路径(Desktop Wallpaper) 利用 Windows 的 API 获取桌面壁纸的实际路径,使用的是 SystemParametersInfo 这个API,此AP ...

  4. java.lang.UnsupportedClassVersionError: Bad version number in .class file 解决方案

    在Myeclipse中运行小应用程序时出现如下异常的解决办法 java.lang.UnsupportedClassVersionError: Bad version number in .class ...

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

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

  6. JAVA 线程学习 - Thread了解

    public class ThreadKnow { private TimeThread timeThread; private boolean flag; public ThreadKnow() { ...

  7. LayoutInflater作用是将layout的xml布局文件实例化为View类对象。

    获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.L ...

  8. shell脚本内与mysql交互

    一: mysqlCMD="mysql -h${MYSQL_HOST}  -P${MYSQL_PORT}  -u${MYSQL_USER} -p${MYSQL_PASS}" crea ...

  9. [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)

    Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14158   Accepted: 5697 ...

  10. SQL Server 性能优化

    今天有位网友找我给他原有的系统数据库优化下查询速度,个人总结了几点对sqlserver的优化 1.Sql查询语句的优化,如:能使用外连接查询出来的尽量别用内连接...,这些个就不废话,如果我使用这个给 ...