小编use*_*197的帖子

按顺序写成jsoncpp(c++)

考虑以下示例,我的来源是

    Json::Value root;
    root["id"]=0;
            Json::Value text;
            text["first"]="i";
            text["second"]="love";
            text["third"]="you";
    root["text"]=text;
    root["type"]="test";
    root["begin"]=1;
    root["end"]=1;
    Json::StyledWriter writer;
    string strJson=writer.write(root);
    cout<<"JSON WriteTest" << endl << strJson <<endl;
Run Code Online (Sandbox Code Playgroud)

我想我应该按照行的顺序编写 json 字段。相反,结果是:

JSON WriteTest
{
   "begin" : 1,
   "end" : 1,
   "id" : 0,
   "text" : {
      "first" : "i",
      "second" : "love",
      "third" : "you"
   },
   "type" : "test"
}
Run Code Online (Sandbox Code Playgroud)

我想要的json格式是

JSON WriteTest
{
   "id" : 0,
   "text" : {
      "first" : "i",
      "second" : "love",
      "third" : "you"
   },
   "type" : "test"
   "begin" …
Run Code Online (Sandbox Code Playgroud)

c++ json jsoncpp

6
推荐指数
1
解决办法
8955
查看次数

标签 统计

c++ ×1

json ×1

jsoncpp ×1