From 9c63de2c52d0779b64634887bb631ec50209fc78 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 25 Oct 2022 11:50:13 +0800 Subject: Doc: add section to QJSValue about converting to JSON This is especially useful if you already have serialization code that can perform strict checks on the data, rather than having to rewrite it to work with QJSValue. Change-Id: I5b12aa9806e187586ac1b41995633a46621f76c9 Reviewed-by: Fabian Kosmale (cherry picked from commit 3ed1304ded8aab93df6bebe5a938c3470725a49c) Reviewed-by: Qt Cherry-pick Bot --- src/qml/jsapi/qjsvalue.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/qml') diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index 7d189e3e41..13bf47ce73 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -142,6 +142,16 @@ integers.append(jsArray.property(i).toInt()); } \endcode + + \section2 Converting to JSON + + It's possible to convert a QJSValue to a JSON type. For example, + to convert to an array, use \l QJSEngine::fromScriptValue(): + + \code + const QJsonValue jsonValue = engine.fromScriptValue(jsValue); + const QJsonArray jsonArray = jsonValue.toArray(); + \endcode */ /*! -- cgit v1.2.3