I'm preparing to make it available under a BSD license. Here's a sample usage scenario from the test suite.
//
// Example JSON usage
//
try {
std::stringstream ss;
json::Parser parser;
// without quotes, and with weird spacing
ss << "{objects:[{id:1, location : [ 0, 0,0]},{id:2,location:[1.25,0.25,4]}]}";
json::Object *object = parser.parse_object(ss);
json::Visitor visitor(object);
json::Visitor obj0 = visitor["objects"][0];
json::Visitor obj1 = visitor["objects"][1];
if ((int)(obj0["id"]) != 1 || (double)(obj0["location"][0]) != 0) {
if (verbose) {
std::cout << "visitor test 0 - failed for obj0\n";
}
passes = false;
}
if ((int)(obj1["id"]) != 2 || (double)(obj1["location"][0]) != 1.25 ||
(double)(obj1["location"][1]) != 0.25 || (double)(obj1["location"][2]) != 4) {
if (verbose) {
std::cout << "visitor test 0 - failed for obj1\n";
}
passes = false;
}
delete object;
}
catch (common::exception &exp) {
passes = false;
std::cout << "parse failed for visitor test 0\n";
std::cout << exp.message << std::endl;
}
No comments:
Post a Comment