0

C++ Boost プロパティ ツリーを使用した次のコードでは、次のような美しい出力が期待されます。

{
  "fruit": {
    "apple": "true",
    "orange": "true"
  },
  "animal": {
    "cat": "true",
    "dog": "true",
    "bird": {
      "duck": "true"
    }
  }
}

実際には私は受け取ります:

{"fruit":{"apple":"true","orange":"true"},"animal":
{"cat":"true","dog":"true","bird":{"duck":"true"}}}

jsonこの結果を美しくする組み込みの方法はありますか?

#include <iostream>
#include <string>
#include <sstream>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>

using boost::property_tree::ptree;
using boost::property_tree::basic_ptree;


int main()
{
    ptree root;

    root.put("fruit.apple", "true");
    root.put("fruit.orange", "true");
    root.put("animal.cat", "true");
    root.put("animal.dog", "true");
    root.put("animal.bird.duck", "true");

    std::ostringstream buf;
    write_json(buf, root, false);
    buf << std::endl;

    std::string json = buf.str();
    std::cout<<json<<std::endl;

    return 0;
}
4

1 に答える 1