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  · 

QJsonValue Class

The QJsonValue class encapsulates a value in JSON. More...

 #include <QJsonValue>

Note: All functions in this class are reentrant.

This class was introduced in Qt 5.0.

Public Types

enum Type { Null, Bool, Double, String, ..., Undefined }

Public Functions

QJsonValue(Type type = Null)
QJsonValue(bool b)
QJsonValue(double n)
QJsonValue(const QString & s)
QJsonValue(QLatin1String s)
QJsonValue(const QJsonArray & a)
QJsonValue(const QJsonObject & o)
QJsonValue(const QJsonValue & other)
QJsonValue(int n)
~QJsonValue()
bool isArray() const
bool isBool() const
bool isDouble() const
bool isNull() const
bool isObject() const
bool isString() const
bool isUndefined() const
QJsonArray toArray(const QJsonArray & defaultValue) const
QJsonArray toArray() const
bool toBool(bool defaultValue = false) const
double toDouble(double defaultValue = 0) const
QJsonObject toObject(const QJsonObject & defaultValue) const
QJsonObject toObject() const
QString toString(const QString & defaultValue = QString()) const
QVariant toVariant() const
Type type() const
bool operator!=(const QJsonValue & other) const
QJsonValue & operator=(const QJsonValue & other)
bool operator==(const QJsonValue & other) const

Static Public Members

QJsonValue fromVariant(const QVariant & variant)

Detailed Description

The QJsonValue class encapsulates a value in JSON.

A value in JSON can be one of 6 basic types:

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

A value can represent any of the above data types. In addition, QJsonValue has one special flag to represent undefined values. This can be queried with isUndefined().

The type of the value can be queried with type() or accessors like isBool(), isString(), and so on. Likewise, the value can be converted to the type stored in it using the toBool(), toString() and so on.

Values are strictly typed internally and contrary to QVariant will not attempt to do any implicit type conversions. This implies that converting to a type that is not stored in the value will return a default constructed return value.

Member Type Documentation

enum QJsonValue::Type

This enum describes the type of the JSON value.

ConstantValueDescription
QJsonValue::Null0x0A Null value
QJsonValue::Bool0x1A boolean value. Use toBool() to convert to a bool.
QJsonValue::Double0x2A double. Use toDouble() to convert to a double.
QJsonValue::String0x3A string. Use toString() to convert to a QString.
QJsonValue::Array0x4An array. Use toArray() to convert to a QJsonArray.
QJsonValue::Object0x5An object. Use toObject() to convert to a QJsonObject.
QJsonValue::Undefined0x80The value is undefined. This is usually returned as an error condition, when trying to read an out of bounds value in an array or a non existant key in an object.

Member Function Documentation

QJsonValue::QJsonValue(Type type = Null)

Creates a QJsonValue of type type.

The default is to create a Null value.

QJsonValue::QJsonValue(bool b)

Creates a value of type Bool, with value b.

QJsonValue::QJsonValue(double n)

Creates a value of type Double, with value n.

QJsonValue::QJsonValue(const QString & s)

Creates a value of type String, with value s.

QJsonValue::QJsonValue(QLatin1String s)

Creates a value of type String, with value s.

QJsonValue::QJsonValue(const QJsonArray & a)

Creates a value of type Array, with value a.

QJsonValue::QJsonValue(const QJsonObject & o)

Creates a value of type Object, with value o.

QJsonValue::QJsonValue(const QJsonValue & other)

Creates a copy of other.

QJsonValue::QJsonValue(int n)

This is an overloaded function.

Creates a value of type Double, with value n.

QJsonValue::~QJsonValue()

Destroys the value.

QJsonValue QJsonValue::fromVariant(const QVariant & variant) [static]

Converts variant to a QJsonValue and returns it.

The conversion will convert QVariant types as follows:

For all other QVariant types a conversion to a QString will be attempted. If the returned string is empty, a Null QJsonValue will be stored, otherwise a String value using the returned QString.

See also toVariant().

bool QJsonValue::isArray() const

bool QJsonValue::isBool() const

bool QJsonValue::isDouble() const

bool QJsonValue::isNull() const

bool QJsonValue::isObject() const

bool QJsonValue::isString() const

bool QJsonValue::isUndefined() const

QJsonArray QJsonValue::toArray(const QJsonArray & defaultValue) const

Converts the value to an array and returns it.

If type() is not Array, the defaultValue will be returned.

QJsonArray QJsonValue::toArray() const

This is an overloaded function.

Converts the value to an array and returns it.

If type() is not Array, a QJsonArray() will be returned.

bool QJsonValue::toBool(bool defaultValue = false) const

Converts the value to a bool and returns it.

If type() is not bool, the defaultValue will be returned.

double QJsonValue::toDouble(double defaultValue = 0) const

Converts the value to a double and returns it.

If type() is not Double, the defaultValue will be returned.

QJsonObject QJsonValue::toObject(const QJsonObject & defaultValue) const

Converts the value to an object and returns it.

If type() is not Object, the defaultValue will be returned.

QJsonObject QJsonValue::toObject() const

This is an overloaded function.

Converts the value to an object and returns it.

If type() is not Object, the QJsonObject() will be returned.

QString QJsonValue::toString(const QString & defaultValue = QString()) const

Converts the value to a QString and returns it.

If type() is not String, the defaultValue will be returned.

QVariant QJsonValue::toVariant() const

Converts the value to a QVariant.

The QJsonValue types will be converted as follows:

ConstantValueDescription
QJsonValue::Null?QVariant()
QJsonValue::Bool?QVariant::Bool(obsolete)
QJsonValue::Double?QVariant::Double(obsolete)
QJsonValue::String?QVariant::String(obsolete)
QJsonValue::Array?QVariantList
QJsonValue::Object?QVariantMap
QJsonValue::Undefined?QVariant()

See also fromVariant().

Type QJsonValue::type() const

Returns the type of the value.

See also QJsonValue::Type.

bool QJsonValue::operator!=(const QJsonValue & other) const

Returns true if the value is not equal to other.

QJsonValue & QJsonValue::operator=(const QJsonValue & other)

Assigns the value stored in other to this object.

bool QJsonValue::operator==(const QJsonValue & other) const

Returns true if the value is equal to other.

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