template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator></div>
<p>Returns the number of elements in a JSON value.</p>
<dlclass="section return"><dt>Returns</dt><dd>The return value depends on the different value types and is defined as follows: <tableclass="doxtable">
<tr>
<th>Value type </th><th>return value </th></tr>
<tr>
<td>null </td><td><code>0</code></td></tr>
<tr>
<td>boolean </td><td><code>1</code></td></tr>
<tr>
<td>string </td><td><code>1</code></td></tr>
<tr>
<td>number </td><td><code>1</code></td></tr>
<tr>
<td>object </td><td>result of function object_t::size() </td></tr>
<tr>
<td>array </td><td>result of function array_t::size() </td></tr>
</table>
</dd></dl>
<dlclass="section user"><dt>Complexity</dt><dd>Constant, as long as <aclass="el"href="classnlohmann_1_1basic__json_ac82abedf356d252e0589850c3d8b35ba.html#ac82abedf356d252e0589850c3d8b35ba">array_t</a> and <aclass="el"href="classnlohmann_1_1basic__json_a63691315292df8e1522b00d37ebb1ffc.html#a63691315292df8e1522b00d37ebb1ffc">object_t</a> satisfy the Container concept; that is, their <aclass="el"href="classnlohmann_1_1basic__json_af49c37bbda87f36170c67f960db3781a.html#af49c37bbda87f36170c67f960db3781a"title="returns the number of elements ">size()</a> functions have constant complexity.</dd></dl>
<dlclass="section user"><dt>Requirements</dt><dd>This function satisfies the Container requirements:<ul>
<li>The complexity is constant.</li>
<li>Has the semantics of <code>std::distance(<aclass="el"href="classnlohmann_1_1basic__json_af4261341695729a8e657b94772f95516.html#af4261341695729a8e657b94772f95516"title="returns an iterator to the first element ">begin()</a>, <aclass="el"href="classnlohmann_1_1basic__json_ad8f84e6fb9bbf9a7bc767962ad0fe3a1.html#ad8f84e6fb9bbf9a7bc767962ad0fe3a1"title="returns an iterator to one past the last element ">end()</a>)</code>.</li>
</ul>
</dd></dl>
<dlclass="section user"><dt>Example</dt><dd>The following code calls <aclass="el"href="classnlohmann_1_1basic__json_af49c37bbda87f36170c67f960db3781a.html#af49c37bbda87f36170c67f960db3781a">size</a> on the different value types. <divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="preprocessor">#include <json.hpp></span></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_html"><divclass="ttname"><ahref="classnlohmann_1_1basic__json.html">nlohmann::basic_json</a></div><divclass="ttdoc">a class to store JSON values </div><divclass="ttdef"><b>Definition:</b> json.hpp:113</div></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522_html_a231b02148577b69a154b2ce2c87a5522aa8cfde6331bd59eb2ac96f8911c4b666"><divclass="ttname"><ahref="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html#a231b02148577b69a154b2ce2c87a5522aa8cfde6331bd59eb2ac96f8911c4b666">nlohmann::basic_json::value_t::object</a></div><divclass="ttdoc">object (unordered set of name/value pairs) </div></div>
<divclass="ttc"id="namespacenlohmann_html"><divclass="ttname"><ahref="namespacenlohmann.html">nlohmann</a></div><divclass="ttdoc">namespace for Niels Lohmann </div><divclass="ttdef"><b>Definition:</b> json.hpp:49</div></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522_html_a231b02148577b69a154b2ce2c87a5522af1f713c9e000f5d3f280adbd124df4f5"><divclass="ttname"><ahref="classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html#a231b02148577b69a154b2ce2c87a5522af1f713c9e000f5d3f280adbd124df4f5">nlohmann::basic_json::value_t::array</a></div><divclass="ttdoc">array (ordered collection of values) </div></div>
<divclass="ttc"id="classnlohmann_1_1basic__json_af49c37bbda87f36170c67f960db3781a_html_af49c37bbda87f36170c67f960db3781a"><divclass="ttname"><ahref="classnlohmann_1_1basic__json_af49c37bbda87f36170c67f960db3781a.html#af49c37bbda87f36170c67f960db3781a">nlohmann::basic_json::size</a></div><divclass="ttdeci">size_type size() const noexcept</div><divclass="ttdoc">returns the number of elements </div><divclass="ttdef"><b>Definition:</b> json.hpp:2321</div></div>
</div><!-- fragment --> Output: <preclass="fragment">0
1
1
1
2
0
5
0
1
</pre> The example code above can be translated with<preclass="fragment">g++ -std=c++11 -Isrc doc/examples/size.cpp -o size </pre>. </dd></dl>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<divid="nav-path"class="navpath"><!-- id is needed for treeview function! -->