void write_formatted(JSONNode n, const char *filename){
  if(n.type()!=JSON_NULL){
    std::string jc = n.write_formatted();
    std::ofstream out(filename);
    out << jc;
    out.close();
  }
}
示例#2
0
ptree currencyHandler::getAllCurrenciesInJsonFormat() {
	JSONNode n(JSON_NODE);

	n.push_back(JSONNode("String Node", "String Value"));
	n.push_back(JSONNode("Integer Node", 42));
	n.push_back(JSONNode("Floating Point Node", 3.14));
	n.push_back(JSONNode("Boolean Node", true));
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	JSONNode n(JSON_NODE);
	n.push_back(JSONNode("RootA", "Hello World"));
	JSONNode c(JSON_ARRAY);
	c.set_name("ArrayOfNumbers");
	c.push_back(JSONNode("", 16));
	c.push_back(JSONNode("", 42));
	c.push_back(JSONNode("", 128));
	n.push_back(c);
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	std::string json = "{\"RootA\":\"Value in parent node\",\"ChildNode\":{\"ChildA\":\"String Value\",\"ChildB\":42}}";
	JSONNode n = libjson::parse(json);
	ParseJSON(n);


	JSONNode n(JSON_NODE);
	n.push_back(JSONNode("RootA", "Value in parent node"));
	JSONNode c(JSON_NODE);
	c.set_name("ChildNode");
	c.push_back(JSONNode("ChildA", "String Value"));
	c.push_back(JSONNode("ChildB", 42));
	n.push_back(c);
	std::string jc = n.write_formatted();
	std::cout << jc << std::endl;


	return allCurrenciesJsonArray;
}