QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
|
Helper utilities for working with JSON and GeoJSON conversions. More...
#include <qgsjsonutils.h>
Static Public Member Functions | |
static Q_INVOKABLE 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 Q_INVOKABLE QVariantList | parseArray (const QString &json, QVariant::Type type=QVariant::Invalid) |
Parse a simple array (depth=1) 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 QVariant | parseJson (const std::string &jsonString) |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and an error is logged to the message log. More... | |
static QVariant | parseJson (const std::string &jsonString, QString &error) |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and the error argument is populated accordingly. More... | |
static QgsFeatureList | stringToFeatureList (const QString &string, const QgsFields &fields=QgsFields(), QTextCodec *encoding=nullptr) |
Attempts to parse a GeoJSON string to a collection of features. More... | |
static QgsFields | stringToFields (const QString &string, QTextCodec *encoding=nullptr) |
Attempts to retrieve the fields from a GeoJSON string representing a collection of features. More... | |
Helper utilities for working with JSON and GeoJSON conversions.
Definition at line 299 of file qgsjsonutils.h.
|
static |
Encodes a value to a JSON string representation, adding appropriate quotations and escaping where required.
value | value to encode |
Definition at line 280 of file qgsjsonutils.cpp.
|
static |
Exports all attributes from a QgsFeature as a JSON map type.
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 317 of file qgsjsonutils.cpp.
|
static |
Exports all attributes from a QgsFeature as a json object.
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 565 of file qgsjsonutils.cpp.
|
static |
Converts a QVariant v to a json object.
Definition at line 410 of file qgsjsonutils.cpp.
|
static |
Parse a simple array (depth=1)
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. |
Definition at line 341 of file qgsjsonutils.cpp.
|
static |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned.
Definition at line 560 of file qgsjsonutils.cpp.
|
static |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and an error is logged to the message log.
Definition at line 465 of file qgsjsonutils.cpp.
|
static |
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and the error argument is populated accordingly.
Definition at line 478 of file qgsjsonutils.cpp.
|
static |
Attempts to parse a GeoJSON string to a collection of features.
It is possible to specify fields to parse specific fields, if not provided, no fields will be included. An encoding can be specified which defaults to UTF-8 if it is nullptr
.
Definition at line 264 of file qgsjsonutils.cpp.
|
static |
Attempts to retrieve the fields from a GeoJSON string representing a collection of features.
An encoding can be specified which defaults to UTF-8 if it is nullptr
.
Definition at line 272 of file qgsjsonutils.cpp.