ejson/ejson_tutorial_read.html

178 lines
45 KiB
HTML

<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- For Mobile Devices -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<title>ejson: Ewol JSON parser: Read an JSON content</title>
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="doxy-boot.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">ejson: Ewol JSON parser 0.8.0</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Main&nbsp;Page</a></li>
<li><a href="pages.html">Related&nbsp;Pages</a></li>
<li><a href="namespaces.html">Namespaces</a></li>
<li><a href="annotated.html">Classes</a></li>
<li><a href="files.html">Files</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Link-libs<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
</ul>
</li>
</ul>
<div id="search-box" class="input-group">
<div class="input-group-btn">
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-search"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">All</a></li>
<li><a href="#">Classes</a></li>
<li><a href="#">Namespaces</a></li>
<li><a href="#">Files</a></li>
<li><a href="#">Functions</a></li>
<li><a href="#">Variables</a></li>
<li><a href="#">Typedefs</a></li>
<li><a href="#">Enumerations</a></li>
<li><a href="#">Enumerator</a></li>
<li><a href="#">Friends</a></li>
<li><a href="#">Macros</a></li>
<li><a href="#">Pages</a></li>
</ul>
</div>
<button id="search-close" type="button" class="close" aria-label="Close">
<span aria-hidden="true"></span>
</button>
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div class="content" id="content">
<div class="container">
<div class="row">
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
<div style="margin-bottom: 15px;margin-top: 60px;">
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Read an JSON content </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#ejson_tutorial_read_file">Read an JSON file </a></li>
<li class="level1"><a href="#ejson_tutorial_read_stream">Read an JSON Stream </a></li>
<li class="level1"><a href="#ejson_tutorial_read_folow">Access at all Element datas </a></li>
<li class="level1"><a href="#ejson_tutorial_read_all">All example file </a></li>
</ul>
</div>
<div class="textblock"><p>The first thing to do when reading or writing a JSON file/stream, is to declare the Document interface</p>
<p>Include ejson </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ejson_8hpp.html">ejson/ejson.hpp</a>&gt;</span></div></div><!-- fragment --><p> Declare document interface </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div></div><!-- fragment --><h1><a class="anchor" id="ejson_tutorial_read_file"></a>
Read an JSON file </h1>
<p>File to read: "read.json" </p><div class="fragment"><div class="line">{</div><div class="line"> &quot;object A&quot;: &quot;bonjour&quot;,</div><div class="line"> &quot;object B&quot;: null,</div><div class="line"> &quot;object C&quot;: true,</div><div class="line"> &quot;object D&quot;: 123854,</div><div class="line"> &quot;object E&quot;: [</div><div class="line"> 1,2,3,54,false</div><div class="line"> ],</div><div class="line"> &quot;object F&quot;: {</div><div class="line"> &quot;a&quot;: 1,</div><div class="line"> &quot;b&quot;: 2</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p>Reading a file is done like this: </p><div class="fragment"><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#ae08ff9bbb26c9b8d2b9572781ecb1380">load</a>(<span class="stringliteral">&quot;DATA:read.json&quot;</span>);</div></div><!-- fragment --><p> The file naming is manage by <a class="elRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html">etk::FSNode</a> that provide "DATA:" start string for internal application asset. You can use external path like "./plop/file.json" too.</p>
<h1><a class="anchor" id="ejson_tutorial_read_stream"></a>
Read an JSON Stream </h1>
<p>Reading a stream is done like this: </p><div class="fragment"><div class="line"> std::string stream = <span class="stringliteral">&quot;{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object A\&quot;:\&quot;bonjour\&quot;,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object B\&quot;:null,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object C\&quot;:true,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object D\&quot;:123854.215,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object E\&quot;:[&quot;</span></div><div class="line"> <span class="stringliteral">&quot; 1,2,3,54,false&quot;</span></div><div class="line"> <span class="stringliteral">&quot; ],&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object F\&quot;:{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;a\&quot;:1,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;b\&quot;:2&quot;</span></div><div class="line"> <span class="stringliteral">&quot; }&quot;</span></div><div class="line"> <span class="stringliteral">&quot;}&quot;</span>;</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#af10b1d008b045520e33fec96d6ca94c1">parse</a>(stream);</div></div><!-- fragment --><p> In C and C++ it is very hard to read string with the \" then to simplify parsing of json the parser engine support the use of simple **'** interface: </p><div class="fragment"><div class="line"> std::string stream = <span class="stringliteral">&quot;{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectA:&#39;bonjour&#39;,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectB:null,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectC:true,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectD:123854.215,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectE:[&quot;</span></div><div class="line"> <span class="stringliteral">&quot; #simple comment one Line&quot;</span></div><div class="line"> <span class="stringliteral">&quot; 1,2,3,54,false&quot;</span></div><div class="line"> <span class="stringliteral">&quot; ],&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectF:{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; a:1,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; b:2&quot;</span></div><div class="line"> <span class="stringliteral">&quot; }&quot;</span></div><div class="line"> <span class="stringliteral">&quot;}&quot;</span>;</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#af10b1d008b045520e33fec96d6ca94c1">parse</a>(stream);</div></div><!-- fragment --><h1><a class="anchor" id="ejson_tutorial_read_folow"></a>
Access at all Element datas </h1>
<p>In an <a class="el" href="classejson_1_1_object.html" title="ejson Object interface { ... }. ">ejson::Object</a> (or <a class="el" href="classejson_1_1_document.html" title="ejson Document interface (acces with the file and stream). ">ejson::Document</a>) the sub-nodes are accessible threw an abstraction class stores in an element name <b>Value</b></p>
<p>Get a value with its name: </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_value.html">ejson::Value</a> element = doc[<span class="stringliteral">&quot;object C&quot;</span>];</div></div><!-- fragment --> <h2>Access to a string in an Object: </h2>
<p>The generic Way to access to an element is to convert it in the corect type: </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_string.html">ejson::String</a> elem = doc[<span class="stringliteral">&quot;object A&quot;</span>].<a class="code" href="classejson_1_1_value.html#a43a3bf8ff0d02f92e8751ea8a16fcaa1">toString</a>();</div><div class="line"> <span class="comment">// Get the value:</span></div><div class="line"> std::string <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709a2063c1608d6e0baf80249c42e2be5804">value</a> = elem.<a class="code" href="classejson_1_1_string.html#ad8fa78302b225c6228ee8d971489726a">get</a>();</div></div><!-- fragment --><p> Commonly you might use like this: </p><div class="fragment"><div class="line"> std::string value = doc[<span class="stringliteral">&quot;object A&quot;</span>].<a class="code" href="classejson_1_1_value.html#a43a3bf8ff0d02f92e8751ea8a16fcaa1">toString</a>().<a class="code" href="classejson_1_1_string.html#ad8fa78302b225c6228ee8d971489726a">get</a>();</div></div><!-- fragment --> <h2>Access to a boolean in an Object: </h2>
<div class="fragment"><div class="line"> <span class="keywordtype">bool</span> value = doc[<span class="stringliteral">&quot;object C&quot;</span>].<a class="code" href="classejson_1_1_value.html#ab759dc22259f15b487a4437df60baf1a">toBoolean</a>().<a class="code" href="classejson_1_1_boolean.html#a4df842959a4ef730174efdd38e21b55f">get</a>();</div></div><!-- fragment --> <h2>Access to a Number in an Object: </h2>
<div class="fragment"><div class="line"> <span class="keywordtype">double</span> value = doc[<span class="stringliteral">&quot;object D&quot;</span>].<a class="code" href="classejson_1_1_value.html#a40e63375796266399a4297b8d2b96f2c">toNumber</a>().<a class="code" href="classejson_1_1_number.html#afe98a17bc93666be54da54bb5bf1d871">get</a>();</div></div><!-- fragment --><h2>Access to a Array in an Object: </h2>
<p>Get the Array </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_array.html">ejson::Array</a> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709af1f713c9e000f5d3f280adbd124df4f5">array</a> = doc[<span class="stringliteral">&quot;object E&quot;</span>].<a class="code" href="classejson_1_1_value.html#abf67a6a98c2fb657cff4290cef39b658">toArray</a>();</div></div><!-- fragment --><p> Move threw all element: </p><div class="fragment"><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itArray: array) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itArray);</div><div class="line"> }</div></div><!-- fragment --><p> Move threw all element in C mode: </p><div class="fragment"><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii&lt;array.size(); ++iii) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; array[iii]);</div><div class="line"> }</div></div><!-- fragment --><h2>Access to a Object in an Object: </h2>
<p>Get the Object </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> obj = doc[<span class="stringliteral">&quot;object F&quot;</span>].<a class="code" href="classejson_1_1_value.html#a91236630d37cad7a8d1256835a9448c8">toObject</a>();</div></div><!-- fragment --><p> Move threw all element: </p><div class="fragment"><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itObj: obj) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itObj);</div><div class="line"> }</div></div><!-- fragment --><p> Move threw all element in C mode: </p><div class="fragment"><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii&lt;obj.size(); ++iii) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; obj[iii]);</div><div class="line"> }</div></div><!-- fragment --><h1>Now we can copy the Object we want </h1>
<p>ejson manage reference object, then it is possible that 2 part of the software access at the same object/element ...</p>
<p>You can copy object to separate or duplicate section.</p>
<p>This is named cloning: </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_value.html">ejson::Value</a> tmpClone = doc[<span class="stringliteral">&quot;object F&quot;</span>].<a class="code" href="classejson_1_1_value.html#af66856fee747c1ee0522c4ddc4a1cb6c">clone</a>();</div></div><!-- fragment --><h1><a class="anchor" id="ejson_tutorial_read_all"></a>
All example file </h1>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;test-debug/debug.hpp&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ejson_8hpp.html">ejson/ejson.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;read.hpp&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> readFromFile() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#ae08ff9bbb26c9b8d2b9572781ecb1380">load</a>(<span class="stringliteral">&quot;DATA:read.json&quot;</span>);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse ret = &quot;</span> &lt;&lt; retParse);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Debug display of the tree:&quot;</span>);</div><div class="line"> doc.<a class="code" href="classejson_1_1_value.html#af897c339ede19f822dac984575d4db50">display</a>();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> readFromString1() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse&quot;</span>);</div><div class="line"> std::string stream = <span class="stringliteral">&quot;{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object A\&quot;:\&quot;bonjour\&quot;,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object B\&quot;:null,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object C\&quot;:true,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object D\&quot;:123854.215,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object E\&quot;:[&quot;</span></div><div class="line"> <span class="stringliteral">&quot; 1,2,3,54,false&quot;</span></div><div class="line"> <span class="stringliteral">&quot; ],&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;object F\&quot;:{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;a\&quot;:1,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; \&quot;b\&quot;:2&quot;</span></div><div class="line"> <span class="stringliteral">&quot; }&quot;</span></div><div class="line"> <span class="stringliteral">&quot;}&quot;</span>;</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#af10b1d008b045520e33fec96d6ca94c1">parse</a>(stream);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse ret = &quot;</span> &lt;&lt; retParse);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Debug display of the tree:&quot;</span>);</div><div class="line"> doc.<a class="code" href="classejson_1_1_value.html#af897c339ede19f822dac984575d4db50">display</a>();</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> readFromString2() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse&quot;</span>);</div><div class="line"> std::string stream = <span class="stringliteral">&quot;{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectA:&#39;bonjour&#39;,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectB:null,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectC:true,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectD:123854.215,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectE:[&quot;</span></div><div class="line"> <span class="stringliteral">&quot; #simple comment one Line&quot;</span></div><div class="line"> <span class="stringliteral">&quot; 1,2,3,54,false&quot;</span></div><div class="line"> <span class="stringliteral">&quot; ],&quot;</span></div><div class="line"> <span class="stringliteral">&quot; objectF:{&quot;</span></div><div class="line"> <span class="stringliteral">&quot; a:1,&quot;</span></div><div class="line"> <span class="stringliteral">&quot; b:2&quot;</span></div><div class="line"> <span class="stringliteral">&quot; }&quot;</span></div><div class="line"> <span class="stringliteral">&quot;}&quot;</span>;</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#af10b1d008b045520e33fec96d6ca94c1">parse</a>(stream);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse ret = &quot;</span> &lt;&lt; retParse);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Debug display of the tree:&quot;</span>);</div><div class="line"> doc.<a class="code" href="classejson_1_1_value.html#af897c339ede19f822dac984575d4db50">display</a>();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> readFull() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse&quot;</span>);</div><div class="line"> <span class="keywordtype">bool</span> retParse = doc.<a class="code" href="classejson_1_1_document.html#ae08ff9bbb26c9b8d2b9572781ecb1380">load</a>(<span class="stringliteral">&quot;DATA:read.json&quot;</span>);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;parse ret = &quot;</span> &lt;&lt; retParse);</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Debug display of the tree:&quot;</span>);</div><div class="line"> doc.<a class="code" href="classejson_1_1_value.html#af897c339ede19f822dac984575d4db50">display</a>();</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;list of Object:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> it: doc) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; it);</div><div class="line"> <span class="keywordflow">if</span> (it.isObject() == <span class="keyword">true</span>) {</div><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> obj = it.<a class="code" href="classejson_1_1_value.html#a91236630d37cad7a8d1256835a9448c8">toObject</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Object has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (obj.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of object:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itObj: obj) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itObj);</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (it.isArray() == <span class="keyword">true</span>) {</div><div class="line"> <a class="code" href="classejson_1_1_array.html">ejson::Array</a> array = it.<a class="code" href="classejson_1_1_value.html#abf67a6a98c2fb657cff4290cef39b658">toArray</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Array has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (array.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of object:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itArray: array) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itArray);</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (it.isBoolean() == <span class="keyword">true</span>) {</div><div class="line"> <a class="code" href="classejson_1_1_boolean.html">ejson::Boolean</a> <span class="keywordtype">boolean</span> = it.<a class="code" href="classejson_1_1_value.html#ab759dc22259f15b487a4437df60baf1a">toBoolean</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Boolean has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">boolean</span>.exist() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; boolean Value:&quot;</span> &lt;&lt; <span class="keywordtype">boolean</span>.<span class="keyword">get</span>());</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (it.isString() == <span class="keyword">true</span>) {</div><div class="line"> <a class="code" href="classejson_1_1_string.html">ejson::String</a> str = it.<a class="code" href="classejson_1_1_value.html#a43a3bf8ff0d02f92e8751ea8a16fcaa1">toString</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::String has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (str.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; String Value:&quot;</span> &lt;&lt; str.<a class="code" href="classejson_1_1_string.html#ad8fa78302b225c6228ee8d971489726a">get</a>());</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (it.isNumber() == <span class="keyword">true</span>) {</div><div class="line"> <a class="code" href="classejson_1_1_number.html">ejson::Number</a> num = it.<a class="code" href="classejson_1_1_value.html#a40e63375796266399a4297b8d2b96f2c">toNumber</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Number has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (num.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">continue</span>;</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Number Value:&quot;</span> &lt;&lt; num.<a class="code" href="classejson_1_1_number.html#afe98a17bc93666be54da54bb5bf1d871">get</a>());</div><div class="line"> }</div><div class="line"> }</div><div class="line"> </div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii&lt;doc.size(); ++iii) {</div><div class="line"> <span class="keywordflow">switch</span> (doc[iii].getType()) {</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709aa8cfde6331bd59eb2ac96f8911c4b666">ejson::valueType::object</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an Object:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709af1f713c9e000f5d3f280adbd124df4f5">ejson::valueType::array</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an Array:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709a84e2c64f38f78ba3ea5c905ab5a2da27">ejson::valueType::boolean</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an Boolean:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709a37a6259cc0c1dae299a7866489dff0bd">ejson::valueType::null</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an Null:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709ab1bc248a7ff2b2e95569f56de68615df">ejson::valueType::number</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an Number:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">case</span> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709ab45cffe084dd3d20d928bee85e7b0f21">ejson::valueType::string</a>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Get an String:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Inknow element:&quot;</span> &lt;&lt; doc.getKey(iii) );</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Direct get node exml:&quot;</span>);</div><div class="line"> <a class="code" href="classejson_1_1_value.html">ejson::Value</a> element = doc[<span class="stringliteral">&quot;object C&quot;</span>];</div><div class="line"> <span class="keywordflow">if</span> (element.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">false</span>) {</div><div class="line"> TEST_ERROR(<span class="stringliteral">&quot;The element does not exist&quot;</span>);</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Read String:&quot;</span>);</div><div class="line"> {</div><div class="line"> <span class="comment">// you can simply change the type of the exml value if you know what it is:</span></div><div class="line"><span class="comment"></span> <a class="code" href="classejson_1_1_string.html">ejson::String</a> elem = doc[<span class="stringliteral">&quot;object A&quot;</span>].<a class="code" href="classejson_1_1_value.html#a43a3bf8ff0d02f92e8751ea8a16fcaa1">toString</a>();</div><div class="line"> <span class="comment">// Get the value:</span></div><div class="line"> std::string value = elem.<a class="code" href="classejson_1_1_string.html#ad8fa78302b225c6228ee8d971489726a">get</a>();</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; String Value:&quot;</span> &lt;&lt; value);</div><div class="line"> }</div><div class="line"> <span class="comment">// or simply:</span></div><div class="line"> {</div><div class="line"> <span class="comment">// Get the value:</span></div><div class="line"><span class="comment"></span> std::string value = doc[<span class="stringliteral">&quot;object A&quot;</span>].toString().get();</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; String Value:&quot;</span> &lt;&lt; value);</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Read Boolean:&quot;</span>);</div><div class="line"> </div><div class="line"> <span class="comment">// Get a Boolean value:</span></div><div class="line"> {</div><div class="line"> <span class="comment">// Get the value:</span></div><div class="line"><span class="comment"></span> <span class="keywordtype">bool</span> value = doc[<span class="stringliteral">&quot;object C&quot;</span>].toBoolean().get();</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Boolean Value:&quot;</span> &lt;&lt; value);</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Read Number:&quot;</span>);</div><div class="line"> </div><div class="line"> <span class="comment">// Get a number value:</span></div><div class="line"> {</div><div class="line"> <span class="comment">// Get the value:</span></div><div class="line"><span class="comment"></span> <span class="keywordtype">double</span> value = doc[<span class="stringliteral">&quot;object D&quot;</span>].toNumber().get();</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; Number Value:&quot;</span> &lt;&lt; value);</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Read Array:&quot;</span>);</div><div class="line"> {</div><div class="line"> <a class="code" href="classejson_1_1_array.html">ejson::Array</a> array = doc[<span class="stringliteral">&quot;object E&quot;</span>].<a class="code" href="classejson_1_1_value.html#abf67a6a98c2fb657cff4290cef39b658">toArray</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Array has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (array.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">true</span>) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of Element in Array:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itArray: array) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itArray);</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of Element in Array (C mode):&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii&lt;array.size(); ++iii) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; array[iii]);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Read Object:&quot;</span>);</div><div class="line"> {</div><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> obj = doc[<span class="stringliteral">&quot;object F&quot;</span>].<a class="code" href="classejson_1_1_value.html#a91236630d37cad7a8d1256835a9448c8">toObject</a>();</div><div class="line"> <span class="comment">// check if the convertion in ejson::Object has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (obj.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">true</span>) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of Element in Object:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itObj: obj) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itObj);</div><div class="line"> }</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of Element in Object (C mode):&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii&lt;obj.size(); ++iii) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; obj[iii]);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> </div><div class="line"> TEST_INFO(<span class="stringliteral">&quot;Clone Object:&quot;</span>);</div><div class="line"> <span class="comment">// in the local system, All element get are not copied but referenced. the to have a copy of an object, you need to clone it :</span></div><div class="line"> {</div><div class="line"> <span class="comment">// Clone object:</span></div><div class="line"><span class="comment"></span> <a class="code" href="classejson_1_1_value.html">ejson::Value</a> tmpClone = doc[<span class="stringliteral">&quot;object F&quot;</span>].<a class="code" href="classejson_1_1_value.html#af66856fee747c1ee0522c4ddc4a1cb6c">clone</a>();</div><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> obj = tmpClone.<a class="code" href="classejson_1_1_value.html#a91236630d37cad7a8d1256835a9448c8">toObject</a>();</div><div class="line"> <span class="comment">// check if the clone and convertion in ejson::Object has been done corectly</span></div><div class="line"> <span class="keywordflow">if</span> (obj.<a class="code" href="classejson_1_1_value.html#a1395a9a11600c8d9d4c0025916d3cb2a">exist</a>() == <span class="keyword">true</span>) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; list of Element in Object:&quot;</span>);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span> itObj: obj) {</div><div class="line"> TEST_INFO(<span class="stringliteral">&quot; &quot;</span> &lt;&lt; itObj);</div><div class="line"> }</div><div class="line"> }</div><div class="line"> }</div><div class="line"> </div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> appl::read() {</div><div class="line"> readFromFile();</div><div class="line"> readFromString1();</div><div class="line"> readFromString1();</div><div class="line"> readFull();</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
Generated on Mon Oct 24 2016 15:35:47 for ejson: Ewol JSON parser by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.12
</small></address>
</body>
</html>