QGIS API Documentation  3.6.0-Noosa (5873452)
Static Public Member Functions | List of all members
QgsJsonUtils Class Reference

Helper utilities for working with JSON and GeoJSON conversions. More...

#include <qgsjsonutils.h>

Static Public Member Functions

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 QVariantList parseArray (const QString &json, QVariant::Type type)
 Parse a simple array (depth=1). 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...
 

Detailed Description

Helper utilities for working with JSON and GeoJSON conversions.

Since
QGIS 2.16

Definition at line 250 of file qgsjsonutils.h.

Member Function Documentation

◆ encodeValue()

QString QgsJsonUtils::encodeValue ( const QVariant &  value)
static

Encodes a value to a JSON string representation, adding appropriate quotations and escaping where required.

Parameters
valuevalue to encode
Returns
encoded value

Definition at line 265 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
featurefeature to export
layeroptional associated vector layer. If specified, this allows richer export utilising settings like the layer's fields widget configuration.
attributeWidgetCachesoptional widget configuration cache. Can be used to speed up exporting the attributes for multiple features from the same layer.

Definition at line 302 of file qgsjsonutils.cpp.

◆ parseArray()

QVariantList QgsJsonUtils::parseArray ( const QString &  json,
QVariant::Type  type 
)
static

Parse a simple array (depth=1).

Parameters
jsonthe JSON to parse
typethe type of the elements
Since
QGIS 3.0

Definition at line 326 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
stringGeoJSON string to parse
fieldsfields collection to use for parsed features
encodingtext 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 255 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
stringGeoJSON string to parse
encodingtext 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 260 of file qgsjsonutils.cpp.


The documentation for this class was generated from the following files: