Baptiste Lepilleur | 4cd8bae | 2007-03-15 22:11:38 +0000 | [diff] [blame^] | 1 | /**
|
| 2 | \mainpage
|
| 3 | \section _intro Introduction
|
| 4 |
|
| 5 | <a HREF="http://www.json.org/">JSON (JavaScript Object Notation)</a>
|
| 6 | is a lightweight data-interchange format.
|
| 7 | It can represents integer, real number, string, an ordered sequence of value, and
|
| 8 | a collection of name/value pairs.
|
| 9 |
|
| 10 | Here is an example of JSON data:
|
| 11 | \verbatim
|
| 12 | // Configuration options
|
| 13 | {
|
| 14 | // Default encoding for text
|
| 15 | "encoding" : "UTF-8",
|
| 16 |
|
| 17 | // Plug-ins loaded at start-up
|
| 18 | "plug-ins" : [
|
| 19 | "python",
|
| 20 | "c++",
|
| 21 | "ruby"
|
| 22 | ],
|
| 23 |
|
| 24 | // Tab indent size
|
| 25 | indent : { length : 3, use_space = true }
|
| 26 | }
|
| 27 | \endverbatim
|
| 28 |
|
| 29 | \section _features Features
|
| 30 | - read and write JSON document
|
| 31 | - rewrite JSON document preserving original comments
|
| 32 |
|
| 33 | \code
|
| 34 | Json::Value root; // will contains the root value after parsing.
|
| 35 | Json::Reader reader;
|
| 36 | bool parsingSuccessful = reader.parse( config_doc, root );
|
| 37 | if ( !parsingSuccessful )
|
| 38 | {
|
| 39 | // report to the user the failure and their locations in the document.
|
| 40 | std::cout << "Failed to parse configuration\n"
|
| 41 | << reader.getFormatedErrorMessages();
|
| 42 | return;
|
| 43 | }
|
| 44 |
|
| 45 | // Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
|
| 46 | // such member.
|
| 47 | std::string encoding = root.get("encoding", "UTF-8" ).asString();
|
| 48 | // Get the value of the member of root named 'encoding', return a 'null' value if
|
| 49 | // there is no such member.
|
| 50 | const Json::Value plugins = root["plug-ins"];
|
| 51 | for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
|
| 52 | loadPlugIn( plugins[index].asString() );
|
| 53 |
|
| 54 | setIndentLength( root["indent"].get("length", 3).asInt() );
|
| 55 | setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
|
| 56 |
|
| 57 | // ...
|
| 58 | // At application shutdown to make the new configuration document:
|
| 59 | // Since Json::Value has implicit constructor for all value types, it is not
|
| 60 | // necessary to explicitely construct the Json::Value object:
|
| 61 | root["encoding"] = getCurrentEncoding();
|
| 62 | root["indent"]["length"] = getCurrentIndentLength();
|
| 63 | root["indent"]["use_space"] = getCurrentIndentUseSpace();
|
| 64 |
|
| 65 | Json::StyledWriter writer;
|
| 66 | // Make a new JSON document for the configuration. Preserve original comments.
|
| 67 | std::string outputConfig = writer.write( root );
|
| 68 | \endcode
|
| 69 |
|
| 70 | \section _plinks Build instructions
|
| 71 | The build instruction are located in the file
|
| 72 | <a HREF="README.txt">README.txt</a> in the top-directory of the project.
|
| 73 |
|
| 74 | Permanent link to the lastest revision of the file in subversion:
|
| 75 | <a HREF="http://svn.sourceforge.net/viewcvs.cgi/jsoncpp/README.txt?view=markup">lastest README.txt</a>
|
| 76 |
|
| 77 | \section _plinks Project links
|
| 78 | - <a HREF="http://jsoncpp.sourceforge.net">json-cpp home</a>
|
| 79 | - <a HREF="http://www.sourceforge.net/projects/jsoncpp">json-cpp sourceforge project</a>
|
| 80 |
|
| 81 | \section _rlinks Related links
|
| 82 | - <a HREF="http://www.json.org/">JSON</a> Specification and alternate language implementations.
|
| 83 | - <a HREF="http://www.yaml.org/">YAML</a> A data format designed for human readability.
|
| 84 | - <a HREF="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ</a>.
|
| 85 |
|
| 86 | \section _license License
|
| 87 | The json-cpp library and this documentation are in Public Domain.
|
| 88 |
|
| 89 | \author Baptiste Lepilleur <blep@users.sourceforge.net>
|
| 90 | */
|