From 28a0e43f385e1f34ca846da5b8aba8666018f920 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 18 Oct 2014 09:19:59 +0200 Subject: [PATCH] [DOC] update doc --- class_ejson__Array.html | 122 ++++++---------- class_ejson__Boolean.html | 58 +++----- class_ejson__Document.html | 74 ++++------ class_ejson__Null.html | 52 ++----- class_ejson__Number.html | 66 +++------ class_ejson__Object.html | 144 ++++++++++-------- class_ejson__String.html | 58 +++----- class_ejson__Value.html | 158 +++++++------------- class_ejson__filePos.html | 56 +++---- enum_ejson__nodeType.html | 97 ------------- index.html | 25 +++- library_ejson.html | 16 +- namespace_ejson.html | 22 ++- tutorial_000_Build.html | 87 +++++++++++ tutorial_001_Read.html | 291 +++++++++++++++++++++++++++++++++++++ tutorial_002_Write.html | 56 +++++++ 16 files changed, 786 insertions(+), 596 deletions(-) delete mode 100644 enum_ejson__nodeType.html create mode 100644 tutorial_000_Build.html create mode 100644 tutorial_001_Read.html create mode 100644 tutorial_002_Write.html diff --git a/class_ejson__Array.html b/class_ejson__Array.html index b9b766b..af1b6a2 100644 --- a/class_ejson__Array.html +++ b/class_ejson__Array.html @@ -17,6 +17,11 @@ +

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

diff --git a/class_ejson__Null.html b/class_ejson__Null.html index 2b845d6..e43af49 100644 --- a/class_ejson__Null.html +++ b/class_ejson__Null.html @@ -17,6 +17,11 @@ +

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

+

Tutorials:


Associate libraries:

-

class: ejson::filePos


Description:

- -

-

Associated Namespace:

+

Tutorials:


Associate libraries:

-

ejson


TODO : Main page ...

+

E-json library

+
+

What is EJSON, and how can I use it?

+EJSON, or Ewol json file interface, is a multi-platform library for creating and reading json file.
+

What languages are supported?

+EJSON is written in C++.
+

Are there any licensing restrictions?

+EJSON is FREE software.
+That allow you to use it for every program you want, including those developing proprietary software, without any license fees or royalties.
+ +

License (DSB)

+Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met:
+ +THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+

Tutorials :


+ + + + diff --git a/tutorial_001_Read.html b/tutorial_001_Read.html new file mode 100644 index 0000000..60cf4cf --- /dev/null +++ b/tutorial_001_Read.html @@ -0,0 +1,291 @@ + + + + + ejson Library + + + + + +
+

read

+
Previous: Build
Next: Write
+

Read a json file

+
Previous: Build example
Next: Write a file

+ +A json file is like a xml, but in a simplest way. +It is in the minimum constituated of: +
+{}
+
+This is the simplest json code.
+for example we will use the next json file : +
+{
+	"element1":25622.53,
+	"element2":"a string...",
+	"is active":false,
+	"NULL element":null,
+	"exampleObject":{
+		"a string":"my super example of string",
+		"a null element":null,
+		"an array element":[
+			12, 25, 65, 654
+		],
+		"a boolean Element":true,
+		"a simple sumber"=156156.343,
+		"an other object":{
+			"plop": 1,
+			"plop2": 2
+		}
+	},
+	"exampleArray":[
+		12,
+		25,
+		65,
+		654,
+		{
+			"plup": true,
+			"plup2": false
+		},
+		true,
+		null,
+		[ 22, 23, 24, 25]
+	}
+}
+

+
+

Open the file


+The first step to open a file is to create the json document:
+
+#include <ejson/ejson.h>
+
+int main() {
+	// declare document
+	ejson::Document doc;
+	...
+}
+

+

Load a stored file


+It is important to remember that the input file is manage by etk, +then the naming form is describe by the class: etk::FSNode
+
+	// read file
+	if (doc.load("DATA:example.json") == false) {
+		APPL_ERROR("An error occured when reading the file...");
+		// TODO : STANDARDIZE ERROR....
+		return -1;
+	}
+

+

Load a file stored in memory


+This step is easyest has a reading in a file.
+In the first step, declare a string containing the json description: +
+	std:string myJson = "{ \"element1\":25622.53, \"element2\":\"a string...\" }";
+

+Now we just need to load the string: +
+	if (doc.parse(myJson) == false) {
+		APPL_ERROR("An error occured when parsing the string");
+		return -1;
+	}
+

+it could be interesting to add some \n in the string to find some error in the json string
+

Access on the data


+now we have the data stored in the doc instance, it could be interesting to access on it.
+Despite of XML interface that is not designed to be keep in memory but just parsed and drop, +the json element is many time use as a simple interface to acces on the data.
+This is the reason for this json interfce is designed for simple acces and use.
+

The simple way


+Read a number value in the doc: +
+	double myValue = doc.getNumberValue("element1", 49);
+	APPL_INFO("Get the element value:" << myValue);
+
+Note that we had a return value, in case of the element is not present or in the wrong form.
+We have the same interface for boolean, string and number: + +These interface methode are availlable for ejson::Document, ejson::Object. +The similar interface are availlable on ejson:Array: + +It could be interesting to remember that the maain node of a json file in an object, +this is the reason that ejson::Document herited of ejson::Object.
+

The generic way


+The classical way to read a json file is to parse it like a xml:
+

Object

+We are now reading all node in an object: +
+	ejson::Object* obj = doc.getObject("exampleObject");
+	// note that the obj is NULL if it not an "Object"
+	if (obj == NULL) {
+		APPL_ERROR("Can not get the object 'exampleObject' in the json file");
+		return -1;
+	}
+
+Note at this point we can parse an object in 2 way:
+1: The fastest but not the best: +
+	for (size_t iii=0; iii < obj->size(); ++iii) {
+		std::string key = obj->getKey(iii);
+		ejson::Value* val = obj[iii];
+		// note that error can appear, then check result...
+		if (val == NULL) {
+			APPL_ERROR("Can not read the object id=" << iii);
+			continue;
+		}
+		switch(val->getType()) {
+			case typeArray: {
+				ejson::Array* myArray = val->toArray();
+				APPL_INFO("Find an Array @" << key);
+				} break;
+			case typeString: {
+				ejson::String* myString = val->toString();
+				APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
+				} break;
+			case typeNumber: {
+				ejson::Number* myNumber = val->toNumber();
+				APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
+				} break;
+			case typeBoolean: {
+				ejson::Boolean* myBoolean = val->toBoolean();
+				APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
+				} break;
+			case typeNull:
+				APPL_INFO("Find a null @" << key);
+				break;
+			case typeObject: {
+				ejson::Object* myObject = val->toObject();
+				APPL_INFO("Find an Object @" << key);
+				} break;
+		}
+	}
+

+2: A more generic way to acces on the elemnts: +
+	stk::vector<std::string> keys = obj->getKeys();
+	for (auto key in keys) {
+		ejson::Value* val = obj[key];
+		// note that error can appear, then check result...
+		if (val == NULL) {
+			APPL_ERROR("Can not read the object key=" << key);
+			continue;
+		}
+		switch(val->getType()) {
+			case typeArray: {
+				ejson::Array* myArray = val->toArray();
+				APPL_INFO("Find an Array @" << key);
+				} break;
+			case typeString: {
+				ejson::String* myString = val->toString();
+				APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
+				} break;
+			case typeNumber: {
+				ejson::Number* myNumber = val->toNumber();
+				APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
+				} break;
+			case typeBoolean: {
+				ejson::Boolean* myBoolean = val->toBoolean();
+				APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
+				} break;
+			case typeNull:
+				APPL_INFO("Find a null @" << key);
+				break;
+			case typeObject: {
+				ejson::Object* myObject = val->toObject();
+				APPL_INFO("Find an Object @" << key);
+				} break;
+		}
+	}
+

+

Array


+We are now reading all node in an Array: +
+	ejson::Array* obj = doc.getArray("exampleArray");
+	// note that the obj is NULL if it not an "Array"
+	if (obj == NULL) {
+		APPL_ERROR("Can not get the array 'exampleArray' in the json file");
+		return -1;
+	}
+

+Note for an array we have only one methode to parse the data :
+
+	for (size_t iii=0; iii < obj->size(); ++iii) {
+		ejson::Value* val = obj[iii];
+		// or ejson::Value* val = obj->get(iii);
+		// note that error can appear, then check result...
+		if (val == NULL) {
+			APPL_ERROR("Can not read the object id=" << iii);
+			continue;
+		}
+		switch(val->getType()) {
+			case typeArray: {
+				ejson::Array* myArray = val->toArray();
+				APPL_INFO("Find an Array @" << key);
+				} break;
+			case typeString: {
+				ejson::String* myString = val->toString();
+				APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
+				} break;
+			case typeNumber: {
+				ejson::Number* myNumber = val->toNumber();
+				APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
+				} break;
+			case typeBoolean: {
+				ejson::Boolean* myBoolean = val->toBoolean();
+				APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
+				} break;
+			case typeNull:
+				APPL_INFO("Find a null @" << key);
+				break;
+			case typeObject: {
+				ejson::Object* myObject = val->toObject();
+				APPL_INFO("Find an Object @" << key);
+				} break;
+		}
+	}
+

+ +It is important to note that many time the user know what type will appear in a list or in an object , then you can directly use: +These fuction automatly cast the resut in the good form (if it is the real one)
+
+ + + diff --git a/tutorial_002_Write.html b/tutorial_002_Write.html new file mode 100644 index 0000000..d6e9a72 --- /dev/null +++ b/tutorial_002_Write.html @@ -0,0 +1,56 @@ + + + + + ejson Library + + + + + +
+

write

+
Previous: Read
+

Write a json file

+
Previous: Read a file
+
+ + +