gpt4 book ai didi

c++ - QJSonArray 到 QString 的转换

转载 作者:可可西里 更新时间:2023-11-01 16:29:48 24 4
gpt4 key购买 nike

我有这 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());

就是这样!

关于c++ - QJSonArray 到 QString 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30698632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com