本文整理汇总了C++中PropertyList::write方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyList::write方法的具体用法?C++ PropertyList::write怎么用?C++ PropertyList::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyList
的用法示例。
在下文中一共展示了PropertyList::write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
json::Object top;
json::Array ary1;
json::Array ary2;
json::Object obj1;
json::Object obj2;
json::Object obj3;
ary1.push_back("Hello");
ary1.push_back("World");
ary1.push_back("Goodbye!");
gcore::String val = ary1[1];
std::cout << "Second element: " << val << std::endl;
obj1["name"] = "James";
obj1["age"] = 35;
obj2["name"] = "Philip";
obj2["age"] = 21;
obj3["name"] = "Chloe";
obj3["age"] = 27;
ary2.push_back(obj1);
ary2.push_back(obj2);
top["myflt"] = json::Value(10.0f);
top["myarray"] = ary1;
top["objarray"] = ary2;
std::cout << "Is a number? " << (top["myflt"].type() == json::Value::NumberType) << std::endl;
std::cout << top["objarray"][1]["name"] << std::endl;
std::cout << top << std::endl;
// --- generic access ---
json::Value all(top);
json::Value &v = all["objarray"];
json::Array &_v = all["objarray"];
_v.push_back(obj3);
v.insert(0, obj3);
v.erase(3);
for (json::ArrayConstIterator ait=v.abegin(); ait!=v.aend(); ++ait)
{
std::cout << "[" << (ait - v.abegin()) << "]" << std::endl;
for (json::ObjectConstIterator oit=ait->obegin(); oit!=ait->oend(); ++oit)
{
std::cout << " " << oit->first << ": " << oit->second << std::endl;
}
}
if (argc > 1)
{
const char *path = argv[1];
std::cout << "Read '" << path << "'..." << std::endl;
json::Value top;
try
{
top.read(path);
std::cout << "Succeeded" << std::endl;
top.write(std::cout);
std::cout << std::endl;
PropertyList pl;
if (top.toPropertyList(pl))
{
pl.write("out.xml");
}
}
catch (json::ParserError &e)
{
std::cout << "Failed: " << e.what() << std::endl;
}
try
{
Parser parser;
parser.parse(path);
}
catch (json::ParserError &e)
{
std::cout << "Failed: " << e.what() << std::endl;
}
}
return 0;
}