You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

md_README.html 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>json-c: `json-c`</title>
  7. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  8. <script type="text/javascript" src="jquery.js"></script>
  9. <script type="text/javascript" src="dynsections.js"></script>
  10. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  11. </head>
  12. <body>
  13. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  14. <div id="titlearea">
  15. <table cellspacing="0" cellpadding="0">
  16. <tbody>
  17. <tr style="height: 56px;">
  18. <td style="padding-left: 0.5em;">
  19. <div id="projectname">json-c
  20. &#160;<span id="projectnumber">0.14</span>
  21. </div>
  22. </td>
  23. </tr>
  24. </tbody>
  25. </table>
  26. </div>
  27. <!-- end header part -->
  28. <!-- Generated by Doxygen 1.8.2 -->
  29. <div id="navrow1" class="tabs">
  30. <ul class="tablist">
  31. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  32. <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  33. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  34. <li><a href="files.html"><span>Files</span></a></li>
  35. </ul>
  36. </div>
  37. </div><!-- top -->
  38. <div class="header">
  39. <div class="headertitle">
  40. <div class="title">`json-c` </div> </div>
  41. </div><!--header-->
  42. <div class="contents">
  43. <div class="textblock"><ol type="1">
  44. <li><a href="#overview">Overview and Build Status</a></li>
  45. <li><a href="#buildunix">Building on Unix</a><ul>
  46. <li><a href="#installprereq">Prerequisites</a></li>
  47. <li><a href="#buildcmds">Build commands</a></li>
  48. </ul>
  49. </li>
  50. <li><a href="#CMake">CMake options</a></li>
  51. <li><a href="#testing">Testing</a></li>
  52. <li><a href="#buildvcpkg">Building with `vcpkg`</a></li>
  53. <li><a href="#linking">Linking to libjson-c</a></li>
  54. <li><a href="#using">Using json-c</a></li>
  55. </ol>
  56. <h2>JSON-C - A JSON implementation in C <a class="anchor" id="overview"></a></h2>
  57. <p>Build Status</p>
  58. <ul>
  59. <li><a href="https://ci.appveyor.com/project/hawicz/json-c">AppVeyor Build</a> <div class="image">
  60. <img src="https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true" alt="AppVeyor Build Status"/>
  61. </div>
  62. </li>
  63. <li><a href="https://travis-ci.org/json-c/json-c">Travis Build</a> <div class="image">
  64. <img src="https://travis-ci.org/json-c/json-c.svg?branch=master" alt="Travis Build Status"/>
  65. </div>
  66. </li>
  67. </ul>
  68. <p>Test Status</p>
  69. <ul>
  70. <li><a href="https://coveralls.io/github/json-c/json-c?branch=master">Coveralls</a> <a href="https://coveralls.io/github/json-c/json-c?branch=master">![Coverage Status](https://coveralls.io/repos/github/json-c/json-c/badge.svg?branch=master)</a></li>
  71. </ul>
  72. <p>JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects. It aims to conform to <a href="https://tools.ietf.org/html/rfc7159">RFC 7159</a>.</p>
  73. <h2>Building on Unix with <code>git</code>, <code>gcc</code> and <code>cmake</code> <a class="anchor" id="buildunix"></a></h2>
  74. <p>Home page for json-c: <a href="https://github.com/json-c/json-c/wiki">https://github.com/json-c/json-c/wiki</a></p>
  75. <h3>Prerequisites: <a class="anchor" id="installprereq"></a></h3>
  76. <ul>
  77. <li><code>gcc</code>, <code>clang</code>, or another C compiler</li>
  78. </ul>
  79. <ul>
  80. <li>cmake&gt;=2.8, &gt;=3.16 recommended</li>
  81. </ul>
  82. <p>To generate docs you'll also need:</p>
  83. <ul>
  84. <li><code>doxygen&gt;=1.8.13</code></li>
  85. </ul>
  86. <p>If you are on a relatively modern system, you'll likely be able to install the prerequisites using your OS's packaging system.</p>
  87. <h3>Install using apt (e.g. Ubuntu 16.04.2 LTS)</h3>
  88. <p>```sh sudo apt install git sudo apt install cmake sudo apt install doxygen # optional sudo apt install valgrind # optional ```</p>
  89. <h3>Build instructions: <a class="anchor" id="buildcmds"></a></h3>
  90. <p><code>json-c</code> GitHub repo: <a href="https://github.com/json-c/json-c">https://github.com/json-c/json-c</a></p>
  91. <p>```sh $ git clone <a href="https://github.com/json-c/json-c.git">https://github.com/json-c/json-c.git</a> $ mkdir json-c-build $ cd json-c-build $ cmake ../json-c # See CMake section below for custom arguments ```</p>
  92. <p>Note: it's also possible to put your build directory inside the json-c source directory, or even not use a separate build directory at all, but certain things might not work quite right (notably, <code>make distcheck</code>)</p>
  93. <p>Then:</p>
  94. <p>```sh $ make $ make test $ make USE_VALGRIND=0 test # optionally skip using valgrind $ make install ```</p>
  95. <h3>Generating documentation with Doxygen:</h3>
  96. <p>The libray documentation can be generated directly from the source codes using Doxygen tool:</p>
  97. <p>```sh </p>
  98. <h1>in build directory</h1>
  99. <p>make doc google-chrome doc/html/index.html ```</p>
  100. <h2>CMake Options <a class="anchor" id="CMake"></a></h2>
  101. <p>The json-c library is built with <a href="https://cmake.org/cmake-tutorial/">CMake</a>, which can take a few options.</p>
  102. <table class="doxtable">
  103. <tr>
  104. <th>Variable </th><th>Type </th><th>Description</th></tr>
  105. <tr>
  106. <td>CMAKE_INSTALL_PREFIX </td><td>String </td><td>The install location. </td></tr>
  107. <tr>
  108. <td>CMAKE_BUILD_TYPE </td><td>String </td><td>Defaults to "debug" </td></tr>
  109. <tr>
  110. <td>BUILD_SHARED_LIBS </td><td>Bool </td><td>The default build generates a dynamic (dll/so) library. Set this to OFF to create a static library instead. </td></tr>
  111. <tr>
  112. <td>ENABLE_RDRAND </td><td>Bool </td><td>Enable RDRAND Hardware RNG Hash Seed </td></tr>
  113. <tr>
  114. <td>ENABLE_THREADING </td><td>Bool </td><td>Enable partial threading support </td></tr>
  115. <tr>
  116. <td>DISABLE_WERROR </td><td>Bool </td><td>Disable use of -Werror </td></tr>
  117. <tr>
  118. <td>DISABLE_BSYMBOLIC </td><td>Bool </td><td>Disable use of -Bsymbolic-functions </td></tr>
  119. </table>
  120. <p>Pass these options as <code>-D</code> on CMake's command-line.</p>
  121. <p>```sh cmake -DBUILD_SHARED_LIBS=OFF ... ```</p>
  122. <h3>Building with partial threading support</h3>
  123. <p>Although json-c does not support fully multi-threaded access to object trees, it has some code to help make its use in threaded programs a bit safer. Currently, this is limited to using atomic operations for <a class="el" href="json__object_8h.html#a675aa3a9cced685dbfd1c1a770a0c3e4">json_object_get()</a> and <a class="el" href="json__object_8h.html#afabf61f932cd64a4122ca8092452eed5">json_object_put()</a>.</p>
  124. <p>Since this may have a performance impact, of at least 3x slower according to <a href="https://stackoverflow.com/a/11609063,">https://stackoverflow.com/a/11609063,</a> it is disabled by default. You may turn it on by adjusting your cmake command with: -DENABLE_THREADING=ON</p>
  125. <p>Separately, the default hash function used for object field keys, lh_char_hash, uses a compare-and-swap operation to ensure the random seed is only generated once. Because this is a one-time operation, it is always compiled in when the compare-and-swap operation is available.</p>
  126. <h3>cmake-configure wrapper script</h3>
  127. <p>For those familiar with the old autoconf/autogen.sh/configure method, there is a <code>cmake-configure</code> wrapper script to ease the transition to cmake.</p>
  128. <p>```sh mkdir build cd build ../cmake-configure &ndash;prefix=/some/install/path make ```</p>
  129. <p>cmake-configure can take a few options.</p>
  130. <table class="doxtable">
  131. <tr>
  132. <th>options </th><th>Description</th></tr>
  133. <tr>
  134. <td>prefix=PREFIX </td><td>install architecture-independent files in PREFIX </td></tr>
  135. <tr>
  136. <td>enable-threading </td><td>Enable code to support partly multi-threaded use </td></tr>
  137. <tr>
  138. <td>enable-rdrand </td><td>Enable RDRAND Hardware RNG Hash Seed generation on supported x86/x64 platforms. </td></tr>
  139. <tr>
  140. <td>enable-shared </td><td>build shared libraries [default=yes] </td></tr>
  141. <tr>
  142. <td>enable-static </td><td>build static libraries [default=yes] </td></tr>
  143. <tr>
  144. <td>disable-Bsymbolic </td><td>Avoid linking with -Bsymbolic-function </td></tr>
  145. <tr>
  146. <td>disable-werror </td><td>Avoid treating compiler warnings as fatal errors </td></tr>
  147. </table>
  148. <h2>Testing: <a class="anchor" id="testing"></a></h2>
  149. <p>By default, if valgrind is available running tests uses it. That can slow the tests down considerably, so to disable it use: ```sh export USE_VALGRIND=0 ```</p>
  150. <p>To run tests a separate build directory is recommended: ```sh mkdir build-test cd build-test </p>
  151. <h1>VALGRIND=1 causes -DVALGRIND=1 to be passed when compiling code</h1>
  152. <h1>which uses slightly slower, but valgrind-safe code.</h1>
  153. <p>VALGRIND=1 cmake .. make</p>
  154. <p>make test </p>
  155. <h1>By default, if valgrind is available running tests uses it.</h1>
  156. <p>make USE_VALGRIND=0 test # optionally skip using valgrind ```</p>
  157. <p>If a test fails, check <code>Testing/Temporary/LastTest.log</code>, <code>tests/testSubDir/${testname}/${testname}.vg.out</code>, and other similar files. If there is insufficient output try: ```sh VERBOSE=1 make test ``` or ```sh JSONC_TEST_TRACE=1 make test ``` and check the log files again.</p>
  158. <h2>Building on Unix and Windows with <code>vcpkg</code> <a class="anchor" id="buildvcpkg"></a></h2>
  159. <p>You can download and install JSON-C using the <a href="https://github.com/Microsoft/vcpkg/">vcpkg</a> dependency manager: </p>
  160. <pre class="fragment">git clone https://github.com/Microsoft/vcpkg.git
  161. cd vcpkg
  162. ./bootstrap-vcpkg.sh
  163. ./vcpkg integrate install
  164. vcpkg install json-c
  165. </pre><p>The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please <a href="https://github.com/Microsoft/vcpkg">create an issue or pull request</a> on the vcpkg repository.</p>
  166. <h2>Linking to <code>libjson-c</code> <a class="anchor" id="linking"></a></h2>
  167. <p>If your system has <code>pkgconfig</code>, then you can just add this to your <code>makefile</code>:</p>
  168. <p>```make CFLAGS += $(shell pkg-config &ndash;cflags json-c) LDFLAGS += $(shell pkg-config &ndash;libs json-c) ```</p>
  169. <p>Without <code>pkgconfig</code>, you would do something like this:</p>
  170. <p>```make JSON_C_DIR=/path/to/json_c/install CFLAGS += -I/include/json-c LDFLAGS+= -L/lib -ljson-c ```</p>
  171. <h2>Using json-c <a class="anchor" id="using"></a></h2>
  172. <p>To use json-c you can either include <a class="el" href="json_8h.html" title="A convenience header that may be included instead of other individual ones.">json.h</a>, or preferrably, one of the following more specific header files:</p>
  173. <ul>
  174. <li><a class="el" href="json__object_8h.html" title="Core json-c API. Start here, or with json_tokener.h.">json_object.h</a> - Core types and methods.</li>
  175. <li><a class="el" href="json__tokener_8h.html" title="Methods to parse an input string into a tree of json_object objects.">json_tokener.h</a> - Methods for parsing and serializing json-c object trees.</li>
  176. <li><a class="el" href="json__pointer_8h.html" title="JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree...">json_pointer.h</a> - JSON Pointer (RFC 6901) implementation for retrieving objects from a json-c object tree.</li>
  177. <li><a class="el" href="json__object__iterator_8h.html" title="An API for iterating over json_type_object objects, styled to be familiar to C++ programmers. Unlike json_object_object_foreach() and json_object_object_foreachC(), this avoids the need to expose json-c internals like lh_entry.">json_object_iterator.h</a> - Methods for iterating over single <a class="el" href="structjson__object.html">json_object</a> instances.</li>
  178. <li><a class="el" href="json__visit_8h.html" title="Methods for walking a tree of objects.">json_visit.h</a> - Methods for walking a tree of json-c objects.</li>
  179. <li><a class="el" href="json__util_8h.html" title="Miscllaneous utility functions and macros.">json_util.h</a> - Miscelleanous utility functions.</li>
  180. </ul>
  181. <p>For a full list of headers see <a href="http://json-c.github.io/json-c/json-c-0.13.1/doc/html/files.html">files.html</a> </p>
  182. </div></div><!-- contents -->
  183. <!-- start footer part -->
  184. <hr class="footer"/><address class="footer"><small>
  185. Generated on Sun Apr 19 2020 03:40:44 for json-c by &#160;<a href="http://www.doxygen.org/index.html">
  186. <img class="footer" src="doxygen.png" alt="doxygen"/>
  187. </a> 1.8.2
  188. </small></address>
  189. </body>
  190. </html>