#include#include int main() { Json::Value array; array.append("apple"); array.append("banana"); array.append("orange"); for (Json::ValueIterator itr = array.begin(); itr != array.end(); ++itr) { std::cout << *itr << std::endl; } return 0; }
apple banana orange
#include#include int main() { Json::Value object; object["name"] = "Alice"; object["age"] = 30; for (Json::ValueIterator itr = object.begin(); itr != object.end(); ++itr) { std::cout << itr.key().asString() << ": " << *itr << std::endl; } return 0; }
name: "Alice" age: 30In this example, a JSON object is created with two key-value pairs. The `begin` function is used to create an iterator pointing to the first element of the object, and a for loop is used to iterate over the elements, printing each key-value pair to the console. The cpp json library is part of the jsoncpp package.