#include <JsonFile.h>
|
| | JsonFile (File jsonFile, const Identifier &defaultProperty, const String &defaultFormat) |
| | Simple helper class for handling json files. It will attempt to create a json file with the given default property and format, or if the given json file already exists, it will attempt to parse it and check it has the default property.
|
| |
| var | getDefaultProperty () const |
| | Get the variant for the default property.
|
| |
| const String & | getDefaultFormat () const |
| | Gets the underlying default formatted json, this is used as a fallback when an invalid input is passed to the JSON file.
|
| |
|
| void | initialise () |
| | Parse the file if it exists, or create it if it doesn't. Data is parsed to m_data;.
|
| |
| void | save () |
| | Call save internal.
|
| |
| void | createJsonFromDefaultFormat () |
| | Generate the JSON file using the default format - used in cases where JSON fails to load.
|
| |
|
| void | saveInternal () |
| | Save any changes made to m_data back to the Json file.
|
| |
◆ JsonFile()
| krotos::JsonFile::JsonFile |
( |
File | jsonFile, |
|
|
const Identifier & | defaultProperty, |
|
|
const String & | defaultFormat ) |
Simple helper class for handling json files. It will attempt to create a json file with the given default property and format, or if the given json file already exists, it will attempt to parse it and check it has the default property.
The json data is parsed to a protected variant object, m_data. This object may be manipulated directly, to make any changes to the data, and saved back to the file using the save() method.
- Parameters
-
| jsonFile | The file to create or parse from if it already exists |
| defaultProperty | The default property. This should be the first json property you expect to find in your json file. This is used as a simple way to validate this json file is the one we expect it to be. e.g. myJsonData_version |
| defaultFormat | The default json template this should use. This will be what is written to the file as a fallback if the file does not exist or there are errors in parsing. |
◆ createJsonFromDefaultFormat()
| void krotos::JsonFile::createJsonFromDefaultFormat |
( |
| ) |
|
|
protected |
Generate the JSON file using the default format - used in cases where JSON fails to load.
◆ getDefaultFormat()
| const String & krotos::JsonFile::getDefaultFormat |
( |
| ) |
const |
|
inline |
Gets the underlying default formatted json, this is used as a fallback when an invalid input is passed to the JSON file.
- Returns
- A const reference to the default format string.
◆ getDefaultProperty()
| var krotos::JsonFile::getDefaultProperty |
( |
| ) |
const |
|
inline |
Get the variant for the default property.
◆ initialise()
| void krotos::JsonFile::initialise |
( |
| ) |
|
|
protected |
Parse the file if it exists, or create it if it doesn't. Data is parsed to m_data;.
◆ save()
| void krotos::JsonFile::save |
( |
| ) |
|
|
protected |
◆ saveInternal()
| void krotos::JsonFile::saveInternal |
( |
| ) |
|
|
private |
Save any changes made to m_data back to the Json file.
◆ m_data
| var krotos::JsonFile::m_data |
|
protected |
◆ m_defaultFormat
| String krotos::JsonFile::m_defaultFormat |
|
private |
◆ m_defaultProperty
| Identifier krotos::JsonFile::m_defaultProperty |
|
private |
◆ m_jsonFile
| File krotos::JsonFile::m_jsonFile |
|
protected |
The documentation for this class was generated from the following files: