/** @file * @author Edouard DUPIN * @copyright 2016, Edouard DUPIN, all right reserved * @license APACHE v2.0 (see license file) */ #include //! [ejson_sample_include] #include //! [ejson_sample_include] #include "read.hpp" static void readFromFile() { //! [ejson_sample_declare_doc] ejson::Document doc; //! [ejson_sample_declare_doc] //! [ejson_sample_read_file] bool retParse = doc.load("DATA:read.json"); //! [ejson_sample_read_file] TEST_INFO("parse ret = " << retParse); TEST_INFO("Debug display of the tree:"); doc.display(); } static void readFromString1() { ejson::Document doc; TEST_INFO("parse"); //! [ejson_sample_read_stream1] std::string stream = "{" " \"object A\":\"bonjour\"," " \"object B\":null," " \"object C\":true," " \"object D\":123854.215," " \"object E\":[" " 1,2,3,54,false" " ]," " \"object F\":{" " \"a\":1," " \"b\":2" " }" "}"; bool retParse = doc.parse(stream); //! [ejson_sample_read_stream1] TEST_INFO("parse ret = " << retParse); TEST_INFO("Debug display of the tree:"); doc.display(); } static void readFromString2() { ejson::Document doc; TEST_INFO("parse"); //! [ejson_sample_read_stream2] std::string stream = "{" " objectA:'bonjour'," " objectB:null," " objectC:true," " objectD:123854.215," " objectE:[" " #simple comment one Line" " 1,2,3,54,false" " ]," " objectF:{" " a:1," " b:2" " }" "}"; bool retParse = doc.parse(stream); //! [ejson_sample_read_stream2] TEST_INFO("parse ret = " << retParse); TEST_INFO("Debug display of the tree:"); doc.display(); } static void readFull() { ejson::Document doc; TEST_INFO("parse"); bool retParse = doc.load("DATA:read.json"); TEST_INFO("parse ret = " << retParse); TEST_INFO("Debug display of the tree:"); doc.display(); TEST_INFO("list of Object:"); for (const auto it: doc) { TEST_INFO(" " << it); if (it.isObject() == true) { ejson::Object obj = it.toObject(); // check if the convertion in ejson::Object has been done corectly if (obj.exist() == false) { continue; } TEST_INFO(" list of object:"); for (const auto itObj: obj) { TEST_INFO(" " << itObj); } } else if (it.isArray() == true) { ejson::Array array = it.toArray(); // check if the convertion in ejson::Array has been done corectly if (array.exist() == false) { continue; } TEST_INFO(" list of object:"); for (const auto itArray: array) { TEST_INFO(" " << itArray); } } else if (it.isBoolean() == true) { ejson::Boolean boolean = it.toBoolean(); // check if the convertion in ejson::Boolean has been done corectly if (boolean.exist() == false) { continue; } TEST_INFO(" boolean Value:" << boolean.get()); } else if (it.isString() == true) { ejson::String str = it.toString(); // check if the convertion in ejson::String has been done corectly if (str.exist() == false) { continue; } TEST_INFO(" String Value:" << str.get()); } else if (it.isNumber() == true) { ejson::Number num = it.toNumber(); // check if the convertion in ejson::Number has been done corectly if (num.exist() == false) { continue; } TEST_INFO(" Number Value:" << num.get()); } } for (size_t iii=0; iii