summaryrefslogtreecommitdiffstats
path: root/src/corelib/json
Commit message (Collapse)AuthorAgeFilesLines
* Add initializer list support in QJsonArrayJędrzej Nowacki2014-07-042-0/+39
| | | | | | | | | | | | | | It allows to create a QJsonArray instance in C++ by using a similar expression to JSON. For example: QJsonArray a = {1, 2, 4}; [ChangeLog][QtCore][QtJson] QJsonArray now supports C++11 initializer lists. Task-number: QTBUG-26606 Change-Id: Icc352e518d9649d24176c89e7113d200d5c50b0d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update doc: match actual compact JSON outputmlpo2014-06-261-1/+1
| | | | | | | Task-number: QTBUG-36682 Change-Id: I0fca746a7838cce49efc243a242bb9bb7119bd9e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* json: Add defaultValue to QJsonValueRef toInt/toBool/toDouble/toStringHolger Hans Peter Freyther2014-06-131-0/+6
| | | | | | | | | | | | | | | | | | Currently QJsonValue and QJsonValueRef behave differently in regard to the default values leading to confusion compile errors depending on which of the two types one is actually using. Before this change it was possible to write: QJsonValue value = jsonObject["item"]; QString name = value.toString(QStringLiteral("default")); but not: QString name = jsonObject["item"].toString(QStringLiteral("default")); Change-Id: Id1185acf339aa3a91e97848e85d068f84552df71 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Complete QJsonValue::fromVariant()Sze Howe Koh2014-03-061-1/+3
| | | | | | | | | | | | | | - QVariant can store (U)Int, (U)LongLong, Float and Double numbers. Previously, QJsonValue::fromVariant() converted Floats into Strings while converting the others to Doubles. - Add unit tests for QJsonValue::fromVariant() [ChangeLog][QtCore][JSON] QJsonValue::fromVariant() will now convert single-precision Floats into Doubles instead of Strings Change-Id: I457adbe29c37ada611d1c6d711c42866d63d4024 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Doc: Clarify QJsonValue::fromVariant() type conversionsSze Howe Koh2014-03-041-12/+40
| | | | | | | | | | It wasn't obvious before that many QMetaType types get converted to the same QJsonValue type. Change-Id: I7bb02cb10b6c8a873e291cdf1e16c6c821d51208 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Doc: Replace obsolete types with their newer counterpartsSze Howe Koh2014-02-252-15/+15
| | | | | | | | | This patch ignores: - Docs for obsolete types themselves - Comparisons between new and obsolete types Change-Id: Id9b1e628255113e7c44520abe0f8a4e0db4a283d Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Remove a not required whitespace when writing JSON in compact formatLars Knoll2014-02-161-1/+1
| | | | | | | Task-number: QTBUG-36682 Change-Id: I0c1c0de850504c8dff20a5ae724cc868d9f983f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Added constructor to QJsonValue for const char *Matt Broadstone2014-01-162-3/+24
| | | | | | | | | | | | | | | | For convenience, it reads more easily (and is somewhat expected) to be able to add a string to a QJsonArray like you might with a QVariantList: QJsonArray() << "string". Previously, QJsonValue provided a private void* ctor to explicitly deny this case because it would implicitly convert to a boolean. This ctor provides a const char* ctor (much like QVariant) that interprets the incoming text as utf8 and creates a String type QJsonValue. [ChangeLog][QtCore][QJsonValue] Added constructor to QJsonValue for const char * Change-Id: Icafa954d3da1fb264f9d0fd7cd1a1d2fbbe15095 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Added convenience methods to QJsonArray for appending QJsonValuesMatt Broadstone2014-01-162-0/+33
| | | | | | | | | | | operators for +, +=, and << were added to QJsonArray to make it easier to work with, and more closely resemble the Qt container classes [ChangeLog][QtCore][QJsonArray] Added convenience methods to QJsonArray for appending QJsonValues Change-Id: I96e0a43015f7c0f980cbbef7f20bd2085ee04795 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Use the new UTF-8 codec in QJsonDocumentThiago Macieira2014-01-092-79/+18
| | | | | | | | | | | | | The encoder is in qjsonwriter.cpp, which requires special handling for ASCII due to the use of escape sequences. The decoder is in qjsonparser.cpp, which only scan one character at a time. As a side-effect, the JSON parser now reports the UTF-8 error in the first character with error, instead of the last. This is probably what should have been expected. Change-Id: I52e5bc30d71466b6a36098b4150c61b2e385d8e9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Add QJsonObject::const_iterator() to correct groupTopi Reinio2013-12-051-0/+2
| | | | | | | | | | | Make QJsonObject::const_iterator() part of the same doc group as the non-const variant. Also add a \since command with the correct value. Task-number: QTBUG-33052 Change-Id: I97fa2cc44dae93decf2b99a1384e37579b7dac46 Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Allow non-character codes in utf8 stringsKurt Pattyn2013-10-172-8/+1
| | | | | | | | | | | | | | | | | | | | | | | | Changed the processing of non-character code handling in the UTF8 codec. Non-character codes are now accepted in QStrings, QUrls and QJson strings. Unit tests were adapted accordingly. For more info about non-character codes, see: http://www.unicode.org/versions/corrigendum9.html [ChangeLog][QtCore][QUtf8] UTF-8 now accepts non-character unicode points; these are not replaced by the replacement character anymore [ChangeLog][QtCore][QUrl] QUrl now fully accepts non-character unicode points; they are encoded as percent characters; they can also be pretty decoded [ChangeLog][QtCore][QJson] The Writer and the Parser now fully accept non-character unicode points. Change-Id: I77cf4f0e6210741eac8082912a0b6118eced4f77 Task-number: QTBUG-33229 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add JSON parsing support to qmake.Morten Johan Sørvig2013-10-178-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add qjson* implementation files from corelib/json to the qmake build. Add a read-only compile mode, enabled by defining QT_JSON_READONLY. Add qmake built-in function parseJson(file, into) which parses a json file into the given variable. qmake uses a flat key -> value-list implementation for storing variables, which means that some hackery is need to represent arbitrarily nested JSON. Use a special "_KEYS_" variable for arrays and objects: Arrays: ["item1", "item2"] $${array._KEYS_} -> 0 1 2 $${array.0} -> "item1" $${array.1} -> "item2" Objects: { "key1" : "value1", "key2" : "value2" } $${object._KEYS_} -> key1 key2 $${object.key1} -> value1 $${object.key2} -> value2 Change-Id: I0aa2e4e4ae14fa25be8242bc16d3cffce32504d2 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Doc: Adding mark-up to boolean default values.Jerome Pasion2013-10-082-13/+13
| | | | | | | | | | | | | | | | | Default values should have mark-up to denote that they are code. This commit changes: -"property is true" to "property is \c true". -"Returns true" to "Returns \c true". -"property is false" to "property is \c false". -"returns true" to "returns \c true". -"returns false" to "returns \c false". src/3rdparty and non-documentation instances were ignored. Task-number: QTBUG-33360 Change-Id: Ie87eaa57af947caa1230602b61c5c46292a4cf4e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-08-275-2/+12
|\ | | | | | | | | | | | | Conflicts: examples/widgets/doc/src/addressbook-fr.qdoc Change-Id: Id1196e8e0c6445f1616c3f29234c974d809f8e48
| * Add json/savegame example.Mitch Curtis2013-08-225-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | There wasn't any example documentation besides json.html, which doesn't actually describe usage of the various QJson* classes. This also makes each QJson* class page link back to json.html. Change-Id: If5ad6493d2728df0cec7bdbbc5790f0b755f816c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Add QJsonValue::toInt().Mitch Curtis2013-08-272-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's a nice feature to have. MSVC also complains about using doubles to create enum values, so the ugly workaround is: enumValue = MyEnum(qRound(json["myEnumValue"].toDouble())); [ChangeLog][QtCore][QJsonValue]Added QJsonValue::toInt(). Change-Id: I1a200b912abf66b2e96390b1980caff26cfa2685 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-08-211-19/+19
|\| | | | | | | | | | | | | | | | | Conflicts: qmake/doc/src/qmake-manual.qdoc src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/src.pro Change-Id: I0a560826c420e46988da3776bd8f9160c365459a
| * Tidy up QJsonObject documentation.Mitch Curtis2013-08-201-19/+19
| | | | | | | | | | | | Change-Id: I445e0573c3c4fdb86ef535299a4eb299e225c15d Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-08-141-2/+6
|\| | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: configure mkspecs/macx-xcode/Info.plist.app mkspecs/macx-xcode/Info.plist.lib qmake/doc/qmake.qdocconf src/corelib/global/qglobal.h tests/auto/other/exceptionsafety/exceptionsafety.pro tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp Change-Id: I3c769a4a82dc2e99a12c69123fbf17613fd2ac2a
| * Fix crashes when invoking toVariant() on empty QJsonValue objects.Friedemann Kleint2013-07-241-2/+6
| | | | | | | | | | Change-Id: I51cd114e862c6fad564484e990348f324ad56ab9 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
| * QtCore: fix the number precision in QJsonDocument.toJson() againLiang Qi2013-07-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | Need to store 17 decimal digits for binary64, IEEE 754 double formats. Autotest is included. Test cases from TC39 test suite for ECMAScript. Task-number: QTBUG-31926 Change-Id: I546398f21ea7ff5e40e89fc9de8703f628f55df9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* | Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-06-041-1/+2
|\| | | | | | | | | | | | | | | Conflicts: src/corelib/global/qglobal.h src/plugins/platforms/cocoa/qnsview.mm Change-Id: I6fe345df5c417cb7a55a3f91285d9b47a22c04fa
| * Fix parsing of long latin strings in the json parserLars Knoll2013-05-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | Latin1 strings are usually stored as 8 bit data in the json binary format. But that data structure has a size limitation of 16bit, so we need to fall back to storing the string as 16 bit data if it is too long. Task-number: QTBUG-30946 Change-Id: I0069b1367030b0b2f819fd1f04e34c9e2534a2a3 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* | Merge remote-tracking branch 'origin/stable' into devFrederik Gladhorn2013-05-236-16/+64
|\| | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qdatastream.cpp src/corelib/io/qdatastream.h src/corelib/json/qjsonwriter.cpp src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/xcb/qxcbkeyboard.cpp Change-Id: I46fef1455f5a9f2ce1ec394a3c65881093c51b62
| * QtCore: fix the number precision in QJsonDocument.toJson()Liang Qi2013-05-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In JSON, any number is stored in double. We need to make sure we keep the maximum possible number precision for integer number. In IEEE 754 double format, the significand precision is 53 bits(52 explicityly stored). Autotest is included. qint64 and double work fine. Task-number: QTBUG-28467 Change-Id: I7f857671c50e4334e9329c778f9b4f090f490540 Reviewed-by: Sune Vuorela <sune@vuorela.dk> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * Fix crashes when creating large documentsLars Knoll2013-05-096-16/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | Compact an object in regular intervals when inserting data into it, to avoid the object becoming huge. Compact an object/array before inserting into another array or object. Check that the document doesn't get so big it's overflowing the internal data structures. Task-number: QTBUG-29288 Change-Id: Id39d80dac1e7d5a11f40819f41b4b336bce16947 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Json writer, support larger signed integers upto 2^53Darryl L. Miles2013-04-122-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | Previously only 32bit signed integers were ensured to be supported by JsonValue type via API but it is expected that a larger integer range should be supported by a JSON implementation. This commit brings the Qt implementation into parity with NodeJS JSON.stringify() in respect of the JavaScript Number type. Change-Id: If91153cb3b13ecc14c50da97055b35ce42f341e7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Json writer, emit full precision for floating point Number typesDarryl L. Miles2013-04-122-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | Previously Qt JSON writer would only emit 6 digits of precision as this is the default with the formatter. However with testing against NodeJS JSON.stringify() this behavior is inconsistent with the defacto standard JSON implementation and conveys a loss of precision. Change-Id: Ie1845a6e0ee0b4c05f63ec0062f372e891855f0b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Json writer, only emit floating point finite numbers, ignore INF/NaNDarryl L. Miles2013-04-122-2/+8
|/ | | | | | | | | | | | | | | | | | | | | | | | My interpretation of RFC4627, Section 2.4 "Numbers" of: Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted. I have also verified this matter with NodeJS JSON.stringify() that emitting a null is consistent behavior with a JSON implementation written in JavaScript. Previously Qt would emit: { plusInfinity: inf, minusInfinity: -inf, notANumber: nan } Which maybe turned into a string values of "inf", "-inf", "nan" by the receiving parser. Now it returns the JSON null value just like NodeJS JSON.stringify(). Change-Id: I9f9c17f12b2606280806c47a9d90465c4ba5f786 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove QT_{BEGIN,END}_HEADER macro usageSergio Ahumada2013-01-294-16/+0
| | | | | | | | | | | The macro was made empty in ba3dc5f3b56d1fab6fe37fe7ae08096d7dc68bcb and is no longer necessary or used. Discussed-on: http://lists.qt-project.org/pipermail/development/2013-January/009284.html Change-Id: Id2bb2e2cabde059305d4af5f12593344ba30f001 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
* Add toJson() formatting argument to QJsonDocument interfaceJean-Paul Delimat2013-01-262-3/+49
| | | | | | | | | | | | | | | | The writer delegate used by QJsonDocument to produce a Json QByteArray supports generating a human readable Json (with spaces and carriage returns that reflect the Json structure) and a less human readable (no spaces nor carriage returns) but more compact Json. The method toJson() was extended with a format argument to support the compact Json generation. Task-number: QTBUG-28815 Change-Id: I8d13849ab9ab6ed7c645011260251dc14a8629d2 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Debao Zhang <hello@debao.me>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-1814-14/+14
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Added missing detach() to QJsonObject::take()Denis Dzyubenko2012-12-131-2/+3
| | | | | | | | | We also need to detach() the taken value in case the compaction triggers and modifies the underlaying data. Change-Id: Idcdeba4236b8e208d107d41be2decbdfc5721300 Reviewed-by: Bjørn Erik Nilsen <post@bjoernen.com> Reviewed-by: Denis Dzyubenko <denis@ddenis.info>
* QtBase: Doc: Fix links to STL-style iteratorsDavid Schulz2012-12-062-8/+8
| | | | | Change-Id: I2822c2a7e9bfc1949c20ff81e08961f641e961fb Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Remove duplicate words and punctuation from documentation.Mitch Curtis2012-09-261-1/+1
| | | | | Change-Id: I5550c62d412510bc2c5acceb2cae7d2f2ef6a8d3 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Fixed crash in moc on big endian platforms.Konstantin Tokarev2012-09-241-1/+1
| | | | | Change-Id: Icaa38eb4b404e5f52248fdeaf9180a5d70d0f5f2 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fixed QJsonDocument::fromBinaryData on big endian platforms.Konstantin Tokarev2012-09-242-4/+4
| | | | | Change-Id: I1786b6222867c8780f6768e5220e7ddff952b28e Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Fixed ifdef condition in QJson resulting in big endian breakage.Konstantin Tokarev2012-09-241-1/+1
| | | | | Change-Id: I3d36d75ff95ad2fe2fcbbe262f9782f0709d7041 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-2214-336/+336
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Removing duplicate includesSergio Ahumada2012-09-092-2/+0
| | | | | | | Do not include a header more than once Change-Id: Ia2e5d66e72988ad833cf5177a3f8aa988bf510e9 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Removed extra detach calls from QJsonArray::takeAtDenis Dzyubenko2012-08-291-6/+1
| | | | | Change-Id: I5711ec6b03e3979eca61f62004a7c6f0eaae79e0 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* doc: Fix some qdoc warningsEskil Abrahamsen Blomfeldt2012-08-231-9/+11
| | | | | | | | | | | QDoc doesn't supported nested tags, and there doesn't seem to be any way to trick it into thinking you've mentioned the argument (\omit didn't work), so actually rephrasing is the only way to kill the warning. Also add a const modifier to a signature to make it match the declaration. Change-Id: Ie02a488c42565205e827602959111c53e2d05a83 Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* Doc: Add \inmodule QtCore to all QtCore class doc bodiesThiago Macieira2012-08-235-0/+10
| | | | | Change-Id: I19100755c97cc155c76a859e19940e9f9222d34e Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* Fix some qdoc errors in the QJson* classesLars Knoll2012-08-202-0/+16
| | | | | Change-Id: If475655445afdba307508c5a3863c4bc8d87ebe6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make the "\internal" qdoc command stand on its own lineLaszlo Papp2012-08-151-1/+2
| | | | | | | | | | The qdoc manual currently claims that the command must stand on its own line. The change follows the consistency with the rest and how the example looks like inside the qdoc manual for this command. Change-Id: I6b653dc95cf9d84e4adf32220dace5d313678419 Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* Fixed most qdoc errors for the json classes.Lars Knoll2012-07-206-39/+221
| | | | | | Change-Id: Ibbbdd7212f6c5e25422bbaa9ccaf4822db52222a Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com> Reviewed-by: Richard J. Moore <rich@kde.org>
* Fix some spelling errorsSergio Ahumada2012-07-112-2/+2
| | | | | | Change-Id: I19d3b2e9a5180b13deb828b55195404ef20be295 Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fixed QJsonObject::find()Denis Dzyubenko2012-06-061-0/+1
| | | | | | | | | | The function returns mutable iterator on the object that can later be passed to e.g. erase(), hence it should detach() to be consistent with QJsonObject::begin() which also detaches. Change-Id: Id79e8e012fd5469e06b68fbc9eecb7c6848ce9c1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
* Replace `const QLatin1String &` with `QLatin1String` where appropriateKonstantin Ritt2012-05-252-2/+2
| | | | | | | Task-Id: QTBUG-24502 Change-Id: I360dee4dc68c165de0631ce4cf34e76fd873080e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>