Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

JSON Support in Qt

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.

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 mmap'able and very fast to access.

More details about the JSON data format can be found at json.org and in RFC-4627.

Overview

JSON is a format to store structured data. It has 6 basic data types:

  • bool
  • double
  • string
  • array
  • object
  • null

Any value can be any of the above type. 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 valid 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 dictionary of key/value pairs. All keys in an object are strings, and an object cannot contain any duplicated keys.

The text representation, of JSON encloses arrays in square brackets ([ ... ]) and objects in curly brackets ({ ... }). The different entries in arrays and objects are separated by commas. The separator between keys and values in an object is a colon (:).

A simple JSON document encoding a person, its age, address and phone numbers could look like:

 {
     "FirstName": "John",
     "LastName": "Doe",
     "Age": 43,
     "Address": {
         "Street": "Downing Street 10",
         "City": "London",
         "Country": "Great Britain"
     },
     "Phone numbers": [
         "+44 1234567",
         "+44 2345678"
     ]
 }

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.

A valid JSON document is either an array or an object, so a document always starts with a square or curly bracket.

The JSON support in Qt consists of a set of 4 classes.

The JSON Classes

The JSON support in Qt consists of these classes:

QJsonArray

Encapsulates a JSON array

QJsonDocument

Way to read and write JSON documents

QJsonObject

Encapsulates a JSON object

QJsonParseError

Used to report errors during JSON parsing

QJsonValue

Encapsulates a value in JSON

QJsonObject::iterator

All JSON classes are value based, implicitly shared classes.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web