Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 262

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- json.qdoc -->
  <title>JSON Support in Qt | Qt Core 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td >JSON Support in Qt</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#overview">Overview</a></li>
<li class="level1"><a href="#the-json-classes">The JSON Classes</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">JSON Support in Qt</h1>
<span class="subtitle"></span>
<!-- $$$json-description -->
<div class="descr"> <a name="details"></a>
<p>Qt provides support for dealing with JSON data. JSON is a format to encode object data derived from Javascript, but now widely used as a data exchange format on the internet.</p>
<p>The JSON support in Qt provides an easy to use C++ API to parse, modify and save JSON data. It also contains support for saving this data in a binary format that is directly &quot;mmap&quot;-able and very fast to access.</p>
<p>More details about the JSON data format can be found at <a href="http://json.org">json.org</a> and in <a href="http://tools.ietf.org/html/rfc4627">RFC-4627</a>.</p>
<a name="overview"></a>
<h4 id="overview">Overview</h4>
<p>JSON is a format to store structured data. It has 6 basic data types:</p>
<ul>
<li>bool</li>
<li>double</li>
<li>string</li>
<li>array</li>
<li>object</li>
<li>null</li>
</ul>
<p>A value can have any of the above types. A boolean value is represented by the strings true or false in JSON. JSON doesn't explicitly specify the valid range for numbers, but the support in Qt is limited to the validity range and precision of doubles. A string can be any valid unicode string. An array is a list of values, and an object is a collection of key/value pairs. All keys in an object are strings, and an object cannot contain any duplicate keys.</p>
<p>The text representation of JSON encloses arrays in square brackets ([ ..&#x2e; ]) and objects in curly brackets ({ ..&#x2e; }). Entries in arrays and objects are separated by commas. The separator between keys and values in an object is a colon (:).</p>
<p>A simple JSON document encoding a person, his/her age, address and phone numbers could look like:</p>
<pre class="cpp">

  {
      <span class="string">&quot;FirstName&quot;</span>: <span class="string">&quot;John&quot;</span><span class="operator">,</span>
      <span class="string">&quot;LastName&quot;</span>: <span class="string">&quot;Doe&quot;</span><span class="operator">,</span>
      <span class="string">&quot;Age&quot;</span>: <span class="number">43</span><span class="operator">,</span>
      <span class="string">&quot;Address&quot;</span>: {
          <span class="string">&quot;Street&quot;</span>: <span class="string">&quot;Downing Street 10&quot;</span><span class="operator">,</span>
          <span class="string">&quot;City&quot;</span>: <span class="string">&quot;London&quot;</span><span class="operator">,</span>
          <span class="string">&quot;Country&quot;</span>: <span class="string">&quot;Great Britain&quot;</span>
      }<span class="operator">,</span>
      <span class="string">&quot;Phone numbers&quot;</span>: <span class="operator">[</span>
          <span class="string">&quot;+44 1234567&quot;</span><span class="operator">,</span>
          <span class="string">&quot;+44 2345678&quot;</span>
      <span class="operator">]</span>
  }

</pre>
<p>The above example consists of an object with 5 key/value pairs. Two of the values are strings, one is a number, one is another object and the last one an array.</p>
<p>A valid JSON document is either an array or an object, so a document always starts with a square or curly bracket.</p>
<a name="the-json-classes"></a>
<h4 id="the-json-classes">The JSON Classes</h4>
<p>All JSON classes are value based, <a href="implicit-sharing.html">implicitly shared classes</a>.</p>
<p>JSON support in Qt consists of these classes:</p>
</div>
<p><b>See also </b><a href="qtcore-serialization-savegame-example.html">JSON Save Game Example</a>.</p>
<!-- @@@json -->
<div class="table"><table class="annotated">
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsonarray.html">QJsonArray</a></p></td><td class="tblDescr"><p>Encapsulates a JSON array</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qjsondocument.html">QJsonDocument</a></p></td><td class="tblDescr"><p>Way to read and write JSON documents</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsonobject.html">QJsonObject</a></p></td><td class="tblDescr"><p>Encapsulates a JSON object</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qjsonparseerror.html">QJsonParseError</a></p></td><td class="tblDescr"><p>Used to report errors during JSON parsing</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsonvalue.html">QJsonValue</a></p></td><td class="tblDescr"><p>Encapsulates a value in JSON</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qjsonobject-const-iterator.html">QJsonObject::const_iterator</a></p></td><td class="tblDescr"><p>QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qjsonobject-iterator.html">QJsonObject::iterator</a></p></td><td class="tblDescr"><p>QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject</p></td></tr>
</table></div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>