本文介绍了JSONCPP写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSONCPP有一个作者,但它似乎只是从解析器获取信息,然后将其输出到字符串或流。

解决方案

<$

如何修改或创建新对象,数组,值,字符串等? p $ p> #include< json / writer.h>

代码:

 code> Json :: Value event; 
Json :: Value vec(Json :: arrayValue);
vec.append(Json :: Value(1));
vec.append(Json :: Value(2));
vec.append(Json :: Value(3));

event [competitors] [home] [name] =利物浦;
event [competitors] [away] [code] = 89223;
event [competitors] [离开] [name] =阿斯顿维拉;
event [competitors] [away] [code] = vec;

std :: cout<<事件< std :: endl;

输出:

 code> {
competitors:
{
away:
{
code:[1,2,3],
name:Aston Villa
},
home:
{
name:Liverpool
}
}
}


JSONCPP has a writer, but all it seems to do is get info from the parser and then output it into a string or a stream. How do I make it alter or create new objects, arrays, values, strings, et cetera and write them into the file?

解决方案
#include<json/writer.h>

Code:

    Json::Value event;   
    Json::Value vec(Json::arrayValue);
    vec.append(Json::Value(1));
    vec.append(Json::Value(2));
    vec.append(Json::Value(3));

    event["competitors"]["home"]["name"] = "Liverpool";
    event["competitors"]["away"]["code"] = 89223;
    event["competitors"]["away"]["name"] = "Aston Villa";
    event["competitors"]["away"]["code"]=vec;

    std::cout << event << std::endl;

Output:

{
        "competitors" : 
        {
                "away" : 
                {
                        "code" : [ 1, 2, 3 ],
                        "name" : "Aston Villa"
                },
                "home" : 
                {
                        "name" : "Liverpool"
                }
        }
}

这篇关于JSONCPP写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:37