jsoncpp.dox 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. \mainpage
  3. \section _intro Introduction
  4. <a HREF="http://www.json.org/">JSON (JavaScript Object Notation)</a>
  5. is a lightweight data-interchange format.
  6. It can represent integer, real number, string, an ordered sequence of value, and
  7. a collection of name/value pairs.
  8. Here is an example of JSON data:
  9. \verbatim
  10. // Configuration options
  11. {
  12. // Default encoding for text
  13. "encoding" : "UTF-8",
  14. // Plug-ins loaded at start-up
  15. "plug-ins" : [
  16. "python",
  17. "c++",
  18. "ruby"
  19. ],
  20. // Tab indent size
  21. "indent" : { "length" : 3, "use_space": true }
  22. }
  23. \endverbatim
  24. \section _features Features
  25. - read and write JSON document
  26. - attach C and C++ style comments to element during parsing
  27. - rewrite JSON document preserving original comments
  28. Notes: Comments used to be supported in JSON but where removed for
  29. portability (C like comments are not supported in Python). Since
  30. comments are useful in configuration/input file, this feature was
  31. preserved.
  32. \section _example Code example
  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.getFormattedErrorMessages();
  42. return;
  43. }
  44. // Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
  45. // such member.
  46. std::string encoding = root.get("encoding", "UTF-8" ).asString();
  47. // Get the value of the member of root named 'encoding', return a 'null' value if
  48. // there is no such member.
  49. const Json::Value plugins = root["plug-ins"];
  50. for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
  51. loadPlugIn( plugins[index].asString() );
  52. setIndentLength( root["indent"].get("length", 3).asInt() );
  53. setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
  54. // ...
  55. // At application shutdown to make the new configuration document:
  56. // Since Json::Value has implicit constructor for all value types, it is not
  57. // necessary to explicitly construct the Json::Value object:
  58. root["encoding"] = getCurrentEncoding();
  59. root["indent"]["length"] = getCurrentIndentLength();
  60. root["indent"]["use_space"] = getCurrentIndentUseSpace();
  61. Json::StyledWriter writer;
  62. // Make a new JSON document for the configuration. Preserve original comments.
  63. std::string outputConfig = writer.write( root );
  64. // You can also use streams. This will put the contents of any JSON
  65. // stream at a particular sub-value, if you'd like.
  66. std::cin >> root["subtree"];
  67. // And you can write to a stream, using the StyledWriter automatically.
  68. std::cout << root;
  69. \endcode
  70. \section _pbuild Build instructions
  71. The build instructions are located in the file
  72. <a HREF="README.txt">README.txt</a> in the top-directory of the project.
  73. Permanent link to the latest revision of the file in subversion:
  74. <a HREF="http://jsoncpp.svn.sourceforge.net/viewvc/jsoncpp/trunk/jsoncpp/README.txt?view=markup">latest README.txt</a>
  75. \section _pdownload Download
  76. The sources can be downloaded from
  77. <a HREF="http://sourceforge.net/projects/jsoncpp/files/">SourceForge download page</a>.
  78. The latest version of the source is available in the project's subversion repository:
  79. <a HREF="http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/">
  80. http://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/</a>
  81. To checkout the source, see the following
  82. <a HREF="http://sourceforge.net/scm/?type=svn&group_id=144446">instructions</a>.
  83. \section _news What's New?
  84. The description of latest changes can be found in
  85. <a HREF="NEWS.txt">NEWS.txt</a> in the top-directory of the project.
  86. Permanent link to the latest revision of the file in subversion:
  87. <a HREF="http://svn.sourceforge.net/viewcvs.cgi/jsoncpp/README.txt?view=markup">latest NEWS.txt</a>
  88. \section _plinks Project links
  89. - <a HREF="http://jsoncpp.sourceforge.net">json-cpp home</a>
  90. - <a HREF="http://www.sourceforge.net/projects/jsoncpp/">json-cpp sourceforge project</a>
  91. \section _rlinks Related links
  92. - <a HREF="http://www.json.org/">JSON</a> Specification and alternate language implementations.
  93. - <a HREF="http://www.yaml.org/">YAML</a> A data format designed for human readability.
  94. - <a HREF="http://www.cl.cam.ac.uk/~mgk25/unicode.html">UTF-8 and Unicode FAQ</a>.
  95. \section _license License
  96. See file <a HREF="LICENSE">LICENSE</a> in the top-directory of the project.
  97. Basically JsonCpp is licensed under MIT license, or public domain if desired
  98. and recognized in your jurisdiction.
  99. \author Baptiste Lepilleur <blep@users.sourceforge.net>
  100. */