5 class Myexcept
: public std::exception
8 Myexcept(std::string message
)
10 ~Myexcept() throw(){};
11 const char* what() const throw()
13 return message
.c_str();
21 std::string json
= "{\"batchcomplete\":\"\",\"query\":{\"normalized\":[{\"from\":\"Amundsen_Basin\",\"to\":\"Amundsen Basin\"}],\"pages\":{\"37082520\":{\"pageid\":37082520,\"ns\":0,\"title\":\"Amundsen Basin\",\"links\":[{\"ns\":0,\"title\":\"Abyssal\"},{\"ns\":0,\"title\":\"Arctic\"},{\"ns\":0,\"title\":\"Arctic Ocean\"},{\"ns\":0,\"title\":\"Cenozoic\"},{\"ns\":0,\"title\":\"Eurasian Basin\"},{\"ns\":0,\"title\":\"Gakkel Ridge\"},{\"ns\":0,\"title\":\"Lomonosov Ridge\"},{\"ns\":0,\"title\":\"Nansen Basin\"},{\"ns\":0,\"title\":\"Roald Amundsen\"},{\"ns\":0,\"title\":\"Seafloor spreading\"},{\"ns\":0,\"title\":\"Wilkes Basin\"}]}}}}";
26 ////std::istringstream jsondatastream(json);
27 ////jsondatastream >> document;
30 // this gives better error reporting?
31 bool success
= reader
.parse(json
, document
, false);
34 throw Myexcept("Error parsing JSON");
37 bool needmoredata
= !document
.isMember("batchcomplete");
40 auto next
= document
.get("query", Json::Value::nullSingleton());
42 if (next
== Json::Value::nullSingleton()) {
43 throw Myexcept("Error parsing JSON - no query result");
46 next
= next
.get("pages", Json::Value::nullSingleton());
48 if (next
== Json::Value::nullSingleton()) {
49 throw Myexcept("Error parsing JSON - no pages result");