Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <jsoncpp/json.h>
- using namespace std;
- void testJsonCpp() {
- std::string s = "{\"col\": \"5\", \"par1\":{\"type\": \"int\",\"value\": \"val\",\"typeGen\": 1}}";
- // Let's parse it
- Json::Value root;
- Json::Reader reader;
- bool parsedSuccess = reader.parse(s,
- root,
- false);
- if (not parsedSuccess) {
- // Report failures and their locations
- // in the document.
- cout << "Failed to parse JSON" << endl
- << reader.getFormatedErrorMessages()
- << endl;
- return;
- }
- Json::Value::Members mem = root.getMemberNames();
- Json::Value child = root[mem[0]];
- cout << "name: " << mem[0] << " child: " << child.asString() << endl;
- for (int i = 1; i < mem.size(); ++i)
- {
- child = root[mem[i]];
- cout << mem[i] << " " << i << " child: " << child.asString() << endl;
- Json::Value::Members childMem = child.getMemberNames();
- cout << child[childMem[0]].asString() << endl << "type";
- cout << child[childMem[1]].asString() << endl << "value";
- cout << child[childMem[2]].asString() << endl << "typeGen";
- }
- // // Let's extract the array contained
- // // in the root object
- // const Json::Value array = root["name"];
- //
- // // Iterate over sequence elements and
- // // print its values
- // for (unsigned int index = 0; index < array.size();
- // ++index) {
- // cout << "Element "
- // << index
- // << " in array: "
- // << array[index].asString()
- // << endl;
- // }
- //
- // // Lets extract the not array element
- // // contained in the root object and
- // // print its value
- // const Json::Value notAnArray =
- // root["not an array"];
- //
- // if (not notAnArray.isNull()) {
- // cout << "Not an array: "
- // << notAnArray.asString()
- // << endl;
- // }
- //
- // // If we want to print JSON is as easy as doing:
- // cout << "Json Example pretty print: "
- // << endl << root.toStyledString()
- // << endl;
- }
- extern "C"
- char * func(char *_s) {
- std::cout << "print cpp extern func 'C': " << _s << std::endl;
- testJsonCpp();
- return _s;
- }
- //g++ -fPIC test.cpp -o test.so -shared
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement