summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/json/qjsonarray.cpp2
-rw-r--r--src/corelib/json/qjsonobject.cpp2
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp33
3 files changed, 35 insertions, 2 deletions
diff --git a/src/corelib/json/qjsonarray.cpp b/src/corelib/json/qjsonarray.cpp
index 433a68105d..6bae2001a1 100644
--- a/src/corelib/json/qjsonarray.cpp
+++ b/src/corelib/json/qjsonarray.cpp
@@ -122,10 +122,10 @@ QJsonArray &QJsonArray::operator =(const QJsonArray &other)
if (d && !d->ref.deref())
delete d;
d = other.d;
- a = other.a;
if (d)
d->ref.ref();
}
+ a = other.a;
return *this;
}
diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp
index cfe71e8959..e14000fac3 100644
--- a/src/corelib/json/qjsonobject.cpp
+++ b/src/corelib/json/qjsonobject.cpp
@@ -125,10 +125,10 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other)
if (d && !d->ref.deref())
delete d;
d = other.d;
- o = other.o;
if (d)
d->ref.ref();
}
+ o = other.o;
return *this;
}
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index f35831c900..079ff6e76b 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -117,6 +117,9 @@ private Q_SLOTS:
void testCompactionError();
void parseUnicodeEscapes();
+
+ void assignObjects();
+ void assignArrays();
private:
QString testDataDir;
};
@@ -1774,5 +1777,35 @@ void TestQtJson::parseUnicodeEscapes()
QCOMPARE(array.first().toString(), result);
}
+void TestQtJson::assignObjects()
+{
+ const char *json =
+ "[ { \"Key\": 1 }, { \"Key\": 2 } ]";
+
+ QJsonDocument doc = QJsonDocument::fromJson(json);
+ QJsonArray array = doc.array();
+
+ QJsonObject object = array.at(0).toObject();
+ QCOMPARE(object.value("Key").toDouble(), 1.);
+
+ object = array.at(1).toObject();
+ QCOMPARE(object.value("Key").toDouble(), 2.);
+}
+
+void TestQtJson::assignArrays()
+{
+ const char *json =
+ "[ [ 1 ], [ 2 ] ]";
+
+ QJsonDocument doc = QJsonDocument::fromJson(json);
+ QJsonArray array = doc.array();
+
+ QJsonArray inner = array.at(0).toArray() ;
+ QCOMPARE(inner.at(0).toDouble(), 1.);
+
+ inner= array.at(1).toArray();
+ QCOMPARE(inner.at(0).toDouble(), 2.);
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"