QJSonArray 到 QString 的转换

QJSonArray to QString conversion

我有这 2 个变量,我想将数据转换为 dataToString。

QJSonArray data;

Qstring dataToString;

在数据中有一个巨大的json像:

{
    "properties": [
        {
            "version":"1",
            "finish":"0",
            "num":3,
            "running":false,
            "time":"00:20:00",
            "player1":"John",
            "player2":"",
            "player3": "Peter",
            "player4":"",
            "team1":"",
            "team2":"",
            "tournament":"",
            "lap":""
        }
    ],
    "game": [
        {
            "serve":true,
            "score":"32",
            "data":"0"
        }
    ]
}

我该怎么做?谢谢

引用the documentation:

You can convert the array to and from text based JSON through QJsonDocument.

换句话说,您需要做的就是:

QJsonArray data;
QJsonDocument doc;
doc.setArray(data);

QString dataToString(doc.toJson());

仅此而已!