2

How to create a QJsonArray from the following QString split at \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";

I want to convert it to a QJsonArray where each line (starting with "Node") would be a separate item. How can I do it in C++ Qt?

Code I tried:

QJsonObject obj_disk;
QJsonArray disk_array;
obj_disk = str.split('\n');
0

1 Answer 1

5

You can use QJsonArray::fromStringList to convert the returned QStringList from str.split(...) into a QJsonArray:

QJsonArray disk_array = QJsonArray::fromStringList(str.split('\n'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.