Skip to content

Commit

Permalink
Merge pull request #31264 from m-kuhn/fix_json
Browse files Browse the repository at this point in the history
Fix variant to json array handling
  • Loading branch information
m-kuhn committed Aug 15, 2019
2 parents 992d261 + 371c7c7 commit 3c52497
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -396,8 +396,8 @@ json QgsJsonUtils::jsonFromVariant( const QVariant &val )
json j;
if ( val.type() == QVariant::Type::Map )
{
const auto vMap { val.toMap() };
auto jMap { json::object() };
const auto vMap = val.toMap();
auto jMap = json::object();
for ( auto it = vMap.constBegin(); it != vMap.constEnd(); it++ )
{
jMap[ it.key().toStdString() ] = jsonFromVariant( it.value() );
Expand All @@ -406,8 +406,8 @@ json QgsJsonUtils::jsonFromVariant( const QVariant &val )
}
else if ( val.type() == QVariant::Type::List )
{
const auto vList{ val.toList() };
auto jList { json::array() };
const auto vList = val.toList();
auto jList = json::array();
for ( const auto &v : vList )
{
jList.push_back( jsonFromVariant( v ) );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -4407,7 +4407,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
QString jRepr;
try
{
const auto jObj { QgsJsonUtils::jsonFromVariant( val ) };
const auto jObj = QgsJsonUtils::jsonFromVariant( val );
if ( ! jObj.is_array() )
{
throw json::parse_error::create( 0, 0, tr( "JSON value must be an array" ).toStdString() );
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgsjsonutils.cpp
Expand Up @@ -124,7 +124,7 @@ void TestQgsJsonUtils::testParseJson()

for ( const auto &testJson : tests )
{
const auto parsed { QgsJsonUtils::parseJson( testJson ) };
const auto parsed = QgsJsonUtils::parseJson( testJson );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( parsed ).dump() ), testJson );
}

Expand Down Expand Up @@ -195,7 +195,7 @@ void TestQgsJsonUtils::testExportAttributesJson()
{
QBENCHMARK
{
const auto json { QgsJsonUtils::exportAttributes( feature, &vl ) };
const auto json = QgsJsonUtils::exportAttributes( feature, &vl );
QCOMPARE( json, QStringLiteral( "{\"fldtxt\":\"a value\",\n\"fldint\":1,\n\"flddbl\":2}" ) );
}
}
Expand All @@ -220,7 +220,7 @@ void TestQgsJsonUtils::testExportFeatureJson()

const auto j( exporter.exportFeatureToJsonObject( feature ) );
QCOMPARE( QString::fromStdString( j.dump() ), expectedJson );
const auto json { exporter.exportFeature( feature ) };
const auto json = exporter.exportFeature( feature );
QCOMPARE( json, expectedJson );

QgsJsonExporter exporterPrecision { &vl, 1 };
Expand Down

0 comments on commit 3c52497

Please sign in to comment.