如何创建以下Qstring的Json数组并将它在\ n分割成新行?
Qstring str = "diskinfo: Node: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 418580779008, Name: C:, Size : 499875049472 \nNode: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: , Name: D:, Size : \nNode: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 324860469248, Name: E:, Size : 487687450624 \nNode: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: 0, Name: F:, Size : 553459712"
我想将它转换为Json数组,并且以node开头的每一行都应该是一个JsonObject?我们可以在QT c ++中做到吗?
尝试过的代码:
QJsonObject obj_disk;
QJsonArray disk_array;
obj_disk = str.split('\n')
答案 0 :(得分:1)
您可以使用QJsonArray::fromStringList
将返回的QStringList从str.split(...)
转换为QJsonArray:
QJsonArray disk_array = QJsonArray::fromStringList(str.split('\n'));