172 lines
24 KiB
HTML
172 lines
24 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: Write 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 Page</a></li>
|
|
<li><a href="pages.html">Related 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">Write 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_write_file">Write an JSON file </a></li>
|
|
<li class="level1"><a href="#ejson_tutorial_write_stream">Write an JSON Stream </a></li>
|
|
<li class="level1"><a href="#ejson_tutorial_write_operation">Operation on Tree </a></li>
|
|
<li class="level1"><a href="#ejson_tutorial_concept">Object concept </a></li>
|
|
<li class="level1"><a href="#ejson_tutorial_write_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 <<a class="code" href="ejson_8hpp.html">ejson/ejson.hpp</a>></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_write_file"></a>
|
|
Write an JSON file </h1>
|
|
<p>Write an json tree is done like: </p><div class="fragment"><div class="line"> <span class="keywordtype">bool</span> retGenerate = doc.<a class="code" href="classejson_1_1_document.html#a2a058bdb1bbd4e151e08e719bbbe2560">store</a>(<span class="stringliteral">"generate.json"</span>);</div></div><!-- fragment --><h1><a class="anchor" id="ejson_tutorial_write_stream"></a>
|
|
Write an JSON Stream </h1>
|
|
<p>Writing a stream is done like this: </p><div class="fragment"><div class="line"> std::string streamOut;</div><div class="line"> <span class="keywordtype">bool</span> retGenerate = doc.<a class="code" href="classejson_1_1_document.html#a81af42d7adbfd3dbc80b3e7ce5ca8f0f">generate</a>(streamOut);</div></div><!-- fragment --> <h1><a class="anchor" id="ejson_tutorial_write_operation"></a>
|
|
Operation on Tree </h1>
|
|
<p>Add String: </p><div class="fragment"><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"A"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"2.5"</span>));</div></div><!-- fragment --><p> Add Null: </p><div class="fragment"><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"B"</span>, <a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div></div><!-- fragment --><p> Add Number: </p><div class="fragment"><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"C"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(2010));</div></div><!-- fragment --><p> Add Boolean: </p><div class="fragment"><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"D"</span>, <a class="code" href="classejson_1_1_boolean.html">ejson::Boolean</a>(<span class="keyword">false</span>));</div></div><!-- fragment --><p> Add Array with values: </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_array.html">ejson::Array</a> array;</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"elem1"</span>));</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_number.html">ejson::Number</a>(22));</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"E"</span>, array);</div></div><!-- fragment --><p> Add Object with values: </p><div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> <a class="code" href="namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709aa8cfde6331bd59eb2ac96f8911c4b666">object</a>;</div><div class="line"> <span class="keywordtype">object</span>.add(<span class="stringliteral">"ee"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"elem1"</span>));</div><div class="line"> <span class="keywordtype">object</span>.add(<span class="stringliteral">"55"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(22));</div><div class="line"> <span class="keywordtype">object</span>.add(<span class="stringliteral">"lk"</span>, <a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"F"</span>, <span class="keywordtype">object</span>);</div></div><!-- fragment --><p> Remove a Value in an Object: </p><div class="fragment"><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a78a30652105b49bd44ded9cc3dbe7072">remove</a>(<span class="stringliteral">"F"</span>);</div></div><!-- fragment --><p> Remove a Value in an Object: </p><div class="fragment"><div class="line"> array.<a class="code" href="classejson_1_1_array.html#a5176745a0aa15435b52adb0be63396fe">remove</a>(2);</div></div><!-- fragment --><h1><a class="anchor" id="ejson_tutorial_concept"></a>
|
|
Object concept </h1>
|
|
<p>The ejson concept is to abstract the implementation of the internal system. All the element are mapped on shared memory. Then if you asign an element to an other, it is the same. You need to clone it if you want to have new standalone element.</p>
|
|
<div class="fragment"><div class="line"> <a class="code" href="classejson_1_1_value.html">ejson::Value</a> tmpClone = doc[<span class="stringliteral">"object F"</span>].<a class="code" href="classejson_1_1_value.html#af66856fee747c1ee0522c4ddc4a1cb6c">clone</a>();</div></div><!-- fragment --> <h1><a class="anchor" id="ejson_tutorial_write_all"></a>
|
|
All example file </h1>
|
|
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include <test-debug/debug.hpp></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="ejson_8hpp.html">ejson/ejson.hpp</a>></span></div><div class="line"><span class="preprocessor">#include "write.hpp"</span></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> writeToFile() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"A"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"2.5"</span>));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"B"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(2010));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"C"</span>, <a class="code" href="classejson_1_1_boolean.html">ejson::Boolean</a>(<span class="keyword">false</span>));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"D"</span>, <a class="code" href="classejson_1_1_array.html">ejson::Array</a>());</div><div class="line"> TEST_INFO(<span class="stringliteral">"store"</span>);</div><div class="line"> <span class="keywordtype">bool</span> retGenerate = doc.<a class="code" href="classejson_1_1_document.html#a2a058bdb1bbd4e151e08e719bbbe2560">store</a>(<span class="stringliteral">"generate.json"</span>);</div><div class="line"> TEST_INFO(<span class="stringliteral">"parse ret = "</span> << retGenerate);</div><div class="line"> TEST_INFO(<span class="stringliteral">"Debug display of the tree:"</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> writeToString() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"A"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"2.5"</span>));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"B"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(2010));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"C"</span>, <a class="code" href="classejson_1_1_boolean.html">ejson::Boolean</a>(<span class="keyword">false</span>));</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"D"</span>, <a class="code" href="classejson_1_1_array.html">ejson::Array</a>());</div><div class="line"> TEST_INFO(<span class="stringliteral">"generate"</span>);</div><div class="line"> std::string streamOut;</div><div class="line"> <span class="keywordtype">bool</span> retGenerate = doc.<a class="code" href="classejson_1_1_document.html#a81af42d7adbfd3dbc80b3e7ce5ca8f0f">generate</a>(streamOut);</div><div class="line"> TEST_INFO(<span class="stringliteral">"parse ret = "</span> << retGenerate);</div><div class="line"> TEST_INFO(<span class="stringliteral">"Debug display of the tree:"</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> writeAll() {</div><div class="line"> <a class="code" href="classejson_1_1_document.html">ejson::Document</a> doc;</div><div class="line"> </div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"A"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"2.5"</span>));</div><div class="line"> </div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"B"</span>, <a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div><div class="line"> </div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"C"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(2010));</div><div class="line"> </div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"D"</span>, <a class="code" href="classejson_1_1_boolean.html">ejson::Boolean</a>(<span class="keyword">false</span>));</div><div class="line"> </div><div class="line"> <a class="code" href="classejson_1_1_array.html">ejson::Array</a> array;</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"elem1"</span>));</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_number.html">ejson::Number</a>(22));</div><div class="line"> array.<a class="code" href="classejson_1_1_array.html#af5bb12b12c4fc35869a32192539c7beb">add</a>(<a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"E"</span>, array);</div><div class="line"> </div><div class="line"> <a class="code" href="classejson_1_1_object.html">ejson::Object</a> object;</div><div class="line"> <span class="keywordtype">object</span>.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"ee"</span>, <a class="code" href="classejson_1_1_string.html">ejson::String</a>(<span class="stringliteral">"elem1"</span>));</div><div class="line"> <span class="keywordtype">object</span>.add(<span class="stringliteral">"55"</span>, <a class="code" href="classejson_1_1_number.html">ejson::Number</a>(22));</div><div class="line"> <span class="keywordtype">object</span>.add(<span class="stringliteral">"lk"</span>, <a class="code" href="classejson_1_1_null.html">ejson::Null</a>());</div><div class="line"> doc.<a class="code" href="classejson_1_1_object.html#a8cec54f55c2b5fb497e6bfc59ea4be13">add</a>(<span class="stringliteral">"F"</span>, <span class="keywordtype">object</span>);</div><div class="line"> </div><div class="line"> <span class="comment">// remove the object named "F"</span></div><div class="line"><span class="comment"></span> doc.<a class="code" href="classejson_1_1_object.html#a78a30652105b49bd44ded9cc3dbe7072">remove</a>(<span class="stringliteral">"F"</span>);</div><div class="line"> </div><div class="line"> <span class="comment">// Remove element 2 in the array</span></div><div class="line"><span class="comment"></span> array.<a class="code" href="classejson_1_1_array.html#a5176745a0aa15435b52adb0be63396fe">remove</a>(2);</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="keywordtype">void</span> appl::write() {</div><div class="line"> writeToFile();</div><div class="line"> writeToString();</div><div class="line"> writeAll();</div><div class="line">}</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  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.12
|
|
</small></address>
|
|
</body>
|
|
</html>
|