summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src/json.qdoc
blob: 98ae202cfa3aca562799219eff9da832c9002594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \group json
    \title JSON Support in Qt
    \ingroup qt-basic-concepts
    \brief An overview of JSON support in Qt.
    \ingroup explanations-dataprocessingandio
    \ingroup frameworks-technologies

    \keyword JSON

    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.

    More details about the JSON data format can be found at \l{http://json.org}{json.org}
    and in \l {RFC 4627}.

    \tableofcontents

    \section1 Overview

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

    \list
    \li bool
    \li double
    \li string
    \li array
    \li object
    \li null
    \endlist

    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.

    The text representation of JSON encloses arrays in square brackets ([ ... ]) and
    objects in curly brackets ({ ... }). 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, his/her age, address and phone numbers could
    look like:

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

    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.

    \sa {Saving and Loading a Game}

    \section1 The JSON Classes

    All JSON classes are value based,
    \l{Implicit Sharing}{implicitly shared classes}.

    JSON support in Qt consists of these classes:
*/