Helper utilities for working with JSON and GeoJSON conversions.
More...
#include <qgsjsonutils.h>
|
static QString | encodeValue (const QVariant &value) |
| Encodes a value to a JSON string representation, adding appropriate quotations and escaping where required. More...
|
|
static QString | exportAttributes (const QgsFeature &feature, QgsVectorLayer *layer=nullptr, const QVector< QVariant > &attributeWidgetCaches=QVector< QVariant >()) |
| Exports all attributes from a QgsFeature as a JSON map type. More...
|
|
static json | exportAttributesToJsonObject (const QgsFeature &feature, QgsVectorLayer *layer=nullptr, const QVector< QVariant > &attributeWidgetCaches=QVector< QVariant >()) |
| Exports all attributes from a QgsFeature as a json object. More...
|
|
static json | jsonFromVariant (const QVariant &v) |
| Converts a QVariant v to a json object. More...
|
|
static QVariantList | parseArray (const QString &json, QVariant::Type type=QVariant::Invalid) |
| Parse a simple array (depth=1) More...
|
|
static QVariant | parseJson (const std::string &jsonString) |
| Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned. More...
|
|
static QVariant | parseJson (const QString &jsonString) |
| Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned. More...
|
|
static QgsFeatureList | stringToFeatureList (const QString &string, const QgsFields &fields, QTextCodec *encoding) |
| Attempts to parse a GeoJSON string to a collection of features. More...
|
|
static QgsFields | stringToFields (const QString &string, QTextCodec *encoding) |
| Attempts to retrieve the fields from a GeoJSON string representing a collection of features. More...
|
|
Helper utilities for working with JSON and GeoJSON conversions.
- Since
- QGIS 2.16
Definition at line 282 of file qgsjsonutils.h.
◆ encodeValue()
QString QgsJsonUtils::encodeValue |
( |
const QVariant & |
value | ) |
|
|
static |
Encodes a value to a JSON string representation, adding appropriate quotations and escaping where required.
- Parameters
-
- Returns
- encoded value
Definition at line 259 of file qgsjsonutils.cpp.
◆ exportAttributes()
QString QgsJsonUtils::exportAttributes |
( |
const QgsFeature & |
feature, |
|
|
QgsVectorLayer * |
layer = nullptr , |
|
|
const QVector< QVariant > & |
attributeWidgetCaches = QVector<QVariant>() |
|
) |
| |
|
static |
Exports all attributes from a QgsFeature as a JSON map type.
- Parameters
-
feature | feature to export |
layer | optional associated vector layer. If specified, this allows richer export utilising settings like the layer's fields widget configuration. |
attributeWidgetCaches | optional widget configuration cache. Can be used to speed up exporting the attributes for multiple features from the same layer. |
Definition at line 296 of file qgsjsonutils.cpp.
◆ exportAttributesToJsonObject()
json QgsJsonUtils::exportAttributesToJsonObject |
( |
const QgsFeature & |
feature, |
|
|
QgsVectorLayer * |
layer = nullptr , |
|
|
const QVector< QVariant > & |
attributeWidgetCaches = QVector<QVariant>() |
|
) |
| |
|
static |
Exports all attributes from a QgsFeature as a json object.
- Parameters
-
feature | feature to export |
layer | optional associated vector layer. If specified, this allows richer export utilising settings like the layer's fields widget configuration. |
attributeWidgetCaches | optional widget configuration cache. Can be used to speed up exporting the attributes for multiple features from the same layer. |
- Note
- Not available in Python bindings
- Since
- QGIS 3.8
Definition at line 516 of file qgsjsonutils.cpp.
◆ jsonFromVariant()
json QgsJsonUtils::jsonFromVariant |
( |
const QVariant & |
v | ) |
|
|
static |
Converts a QVariant v to a json object.
- Note
- Not available in Python bindings
- Since
- QGIS 3.8
Definition at line 389 of file qgsjsonutils.cpp.
◆ parseArray()
QVariantList QgsJsonUtils::parseArray |
( |
const QString & |
json, |
|
|
QVariant::Type |
type = QVariant::Invalid |
|
) |
| |
|
static |
Parse a simple array (depth=1)
- Parameters
-
json | the JSON to parse |
type | optional variant type of the elements, if specified (and not Invalid), the array items will be converted to the type, and discarded if the conversion is not possible. |
- Since
- QGIS 3.0
Definition at line 320 of file qgsjsonutils.cpp.
◆ parseJson() [1/2]
QVariant QgsJsonUtils::parseJson |
( |
const std::string & |
jsonString | ) |
|
|
static |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned.
- Note
- Not available in Python bindings
- Since
- QGIS 3.8
Definition at line 441 of file qgsjsonutils.cpp.
◆ parseJson() [2/2]
QVariant QgsJsonUtils::parseJson |
( |
const QString & |
jsonString | ) |
|
|
static |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned.
- Note
- Not available in Python bindings
- Since
- QGIS 3.8
Definition at line 511 of file qgsjsonutils.cpp.
◆ stringToFeatureList()
QgsFeatureList QgsJsonUtils::stringToFeatureList |
( |
const QString & |
string, |
|
|
const QgsFields & |
fields, |
|
|
QTextCodec * |
encoding |
|
) |
| |
|
static |
Attempts to parse a GeoJSON string to a collection of features.
- Parameters
-
string | GeoJSON string to parse |
fields | fields collection to use for parsed features |
encoding | text encoding |
- Returns
- list of parsed features, or an empty list if no features could be parsed
- See also
- stringToFields()
- Note
- this function is a wrapper around QgsOgrUtils::stringToFeatureList()
Definition at line 249 of file qgsjsonutils.cpp.
◆ stringToFields()
QgsFields QgsJsonUtils::stringToFields |
( |
const QString & |
string, |
|
|
QTextCodec * |
encoding |
|
) |
| |
|
static |
Attempts to retrieve the fields from a GeoJSON string representing a collection of features.
- Parameters
-
string | GeoJSON string to parse |
encoding | text encoding |
- Returns
- retrieved fields collection, or an empty list if no fields could be determined from the string
- See also
- stringToFeatureList()
- Note
- this function is a wrapper around QgsOgrUtils::stringToFields()
Definition at line 254 of file qgsjsonutils.cpp.
The documentation for this class was generated from the following files: