[DOC] update new api
This commit is contained in:
parent
41c52147cd
commit
05b418a6e3
@ -134,9 +134,9 @@ The classical way to read a json file is to parse it like a xml:
|
|||||||
==== Object ====
|
==== Object ====
|
||||||
We are now reading all node in an object:
|
We are now reading all node in an object:
|
||||||
[code style=c++]
|
[code style=c++]
|
||||||
ejson::Object* obj = doc.getObject("exampleObject");
|
std::shared_ptr<ejson::Object> obj = doc.getObject("exampleObject");
|
||||||
// note that the obj is NULL if it not an "Object"
|
// note that the obj is NULL if it not an "Object"
|
||||||
if (obj == NULL) {
|
if (obj == nullptr) {
|
||||||
APPL_ERROR("Can not get the object 'exampleObject' in the json file");
|
APPL_ERROR("Can not get the object 'exampleObject' in the json file");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -147,34 +147,34 @@ Note at this point we can parse an object in 2 way:
|
|||||||
[code style=c++]
|
[code style=c++]
|
||||||
for (size_t iii=0; iii < obj->size(); ++iii) {
|
for (size_t iii=0; iii < obj->size(); ++iii) {
|
||||||
std::string key = obj->getKey(iii);
|
std::string key = obj->getKey(iii);
|
||||||
ejson::Value* val = obj[iii];
|
std::shared_ptr<ejson::Value> val = obj[iii];
|
||||||
// note that error can appear, then check result...
|
// note that error can appear, then check result...
|
||||||
if (val == NULL) {
|
if (val == nullptr) {
|
||||||
APPL_ERROR("Can not read the object id=" << iii);
|
APPL_ERROR("Can not read the object id=" << iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch(val->getType()) {
|
switch(val->getType()) {
|
||||||
case typeArray: {
|
case typeArray: {
|
||||||
ejson::Array* myArray = val->toArray();
|
std::shared_ptr<ejson::Array> myArray = val->toArray();
|
||||||
APPL_INFO("Find an Array @" << key);
|
APPL_INFO("Find an Array @" << key);
|
||||||
} break;
|
} break;
|
||||||
case typeString: {
|
case typeString: {
|
||||||
ejson::String* myString = val->toString();
|
std::shared_ptr<ejson::String> myString = val->toString();
|
||||||
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNumber: {
|
case typeNumber: {
|
||||||
ejson::Number* myNumber = val->toNumber();
|
std::shared_ptr<ejson::Number> myNumber = val->toNumber();
|
||||||
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeBoolean: {
|
case typeBoolean: {
|
||||||
ejson::Boolean* myBoolean = val->toBoolean();
|
std::shared_ptr<ejson::Boolean> myBoolean = val->toBoolean();
|
||||||
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNull:
|
case typeNull:
|
||||||
APPL_INFO("Find a null @" << key);
|
APPL_INFO("Find a null @" << key);
|
||||||
break;
|
break;
|
||||||
case typeObject: {
|
case typeObject: {
|
||||||
ejson::Object* myObject = val->toObject();
|
std::shared_ptr<ejson::Object> myObject = val->toObject();
|
||||||
APPL_INFO("Find an Object @" << key);
|
APPL_INFO("Find an Object @" << key);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -185,34 +185,34 @@ Note at this point we can parse an object in 2 way:
|
|||||||
[code style=c++]
|
[code style=c++]
|
||||||
stk::vector<std::string> keys = obj->getKeys();
|
stk::vector<std::string> keys = obj->getKeys();
|
||||||
for (auto key in keys) {
|
for (auto key in keys) {
|
||||||
ejson::Value* val = obj[key];
|
std::shared_ptr<ejson::Value> val = obj[key];
|
||||||
// note that error can appear, then check result...
|
// note that error can appear, then check result...
|
||||||
if (val == NULL) {
|
if (val == nullptr) {
|
||||||
APPL_ERROR("Can not read the object key=" << key);
|
APPL_ERROR("Can not read the object key=" << key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch(val->getType()) {
|
switch(val->getType()) {
|
||||||
case typeArray: {
|
case typeArray: {
|
||||||
ejson::Array* myArray = val->toArray();
|
std::shared_ptr<ejson::Array> myArray = val->toArray();
|
||||||
APPL_INFO("Find an Array @" << key);
|
APPL_INFO("Find an Array @" << key);
|
||||||
} break;
|
} break;
|
||||||
case typeString: {
|
case typeString: {
|
||||||
ejson::String* myString = val->toString();
|
std::shared_ptr<ejson::String> myString = val->toString();
|
||||||
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNumber: {
|
case typeNumber: {
|
||||||
ejson::Number* myNumber = val->toNumber();
|
std::shared_ptr<ejson::Number> myNumber = val->toNumber();
|
||||||
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeBoolean: {
|
case typeBoolean: {
|
||||||
ejson::Boolean* myBoolean = val->toBoolean();
|
std::shared_ptr<ejson::Boolean> myBoolean = val->toBoolean();
|
||||||
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNull:
|
case typeNull:
|
||||||
APPL_INFO("Find a null @" << key);
|
APPL_INFO("Find a null @" << key);
|
||||||
break;
|
break;
|
||||||
case typeObject: {
|
case typeObject: {
|
||||||
ejson::Object* myObject = val->toObject();
|
std::shared_ptr<ejson::Object> myObject = val->toObject();
|
||||||
APPL_INFO("Find an Object @" << key);
|
APPL_INFO("Find an Object @" << key);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -223,9 +223,9 @@ Note at this point we can parse an object in 2 way:
|
|||||||
|
|
||||||
We are now reading all node in an Array:
|
We are now reading all node in an Array:
|
||||||
[code style=c++]
|
[code style=c++]
|
||||||
ejson::Array* obj = doc.getArray("exampleArray");
|
std::shared_ptr<ejson::Array> obj = doc.getArray("exampleArray");
|
||||||
// note that the obj is NULL if it not an "Array"
|
// note that the obj is nullptr if it not an "Array"
|
||||||
if (obj == NULL) {
|
if (obj == nullptr) {
|
||||||
APPL_ERROR("Can not get the array 'exampleArray' in the json file");
|
APPL_ERROR("Can not get the array 'exampleArray' in the json file");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -235,35 +235,35 @@ Note for an array we have only one methode to parse the data :
|
|||||||
|
|
||||||
[code style=c++]
|
[code style=c++]
|
||||||
for (size_t iii=0; iii < obj->size(); ++iii) {
|
for (size_t iii=0; iii < obj->size(); ++iii) {
|
||||||
ejson::Value* val = obj[iii];
|
std::shared_ptr<ejson::Value> val = obj[iii];
|
||||||
// or ejson::Value* val = obj->get(iii);
|
// or std::shared_ptr<ejson::Value> val = obj->get(iii);
|
||||||
// note that error can appear, then check result...
|
// note that error can appear, then check result...
|
||||||
if (val == NULL) {
|
if (val == nullptr) {
|
||||||
APPL_ERROR("Can not read the object id=" << iii);
|
APPL_ERROR("Can not read the object id=" << iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch(val->getType()) {
|
switch(val->getType()) {
|
||||||
case typeArray: {
|
case typeArray: {
|
||||||
ejson::Array* myArray = val->toArray();
|
std::shared_ptr<ejson::Array> myArray = val->toArray();
|
||||||
APPL_INFO("Find an Array @" << key);
|
APPL_INFO("Find an Array @" << key);
|
||||||
} break;
|
} break;
|
||||||
case typeString: {
|
case typeString: {
|
||||||
ejson::String* myString = val->toString();
|
std::shared_ptr<ejson::String> myString = val->toString();
|
||||||
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
APPL_INFO("Find a String @" << key << " value='" << myString->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNumber: {
|
case typeNumber: {
|
||||||
ejson::Number* myNumber = val->toNumber();
|
std::shared_ptr<ejson::Number> myNumber = val->toNumber();
|
||||||
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
APPL_INFO("Find a Number @" << key << " value='" << myNumber->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeBoolean: {
|
case typeBoolean: {
|
||||||
ejson::Boolean* myBoolean = val->toBoolean();
|
std::shared_ptr<ejson::Boolean> myBoolean = val->toBoolean();
|
||||||
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
APPL_INFO("Find a Boolean @" << key << " value='" << myBoolean->get() << "'");
|
||||||
} break;
|
} break;
|
||||||
case typeNull:
|
case typeNull:
|
||||||
APPL_INFO("Find a null @" << key);
|
APPL_INFO("Find a null @" << key);
|
||||||
break;
|
break;
|
||||||
case typeObject: {
|
case typeObject: {
|
||||||
ejson::Object* myObject = val->toObject();
|
std::shared_ptr<ejson::Object> myObject = val->toObject();
|
||||||
APPL_INFO("Find an Object @" << key);
|
APPL_INFO("Find an Object @" << key);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@ -278,5 +278,5 @@ It is important to note that many time the user know what type will appear in a
|
|||||||
:** [methode[ejson::Array::getObject]]
|
:** [methode[ejson::Array::getObject]]
|
||||||
:** [methode[ejson::Array::getBoolean]]
|
:** [methode[ejson::Array::getBoolean]]
|
||||||
:** [methode[ejson::Array::getstring]]
|
:** [methode[ejson::Array::getstring]]
|
||||||
These fuction automatly cast the resut in the good form (if it is the real one)
|
These fuction automatly cast the result in the good form (if it is the real one)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user