Save New line in JSON file in QT

146 Views Asked by At

I have a QString eg:

QString test = "Hello";
test += "\n";
test += "World";

I am saving this in a file :


QFile file("test.json");
if (!file.open(QIODevice::WriteOnly )) return;

jsonObj = QJsonObject()
jsonObj.insert("Key",test);

QJsonDocument doc;
doc.setObject(jsonObj);
file.write(doc.toJson());
file.close();

Now the output test.json file is:

{
"Key":"Hello\nWorld"
}

My desired output is:

{
"Key":"Hello
World"
}

The reason for doing it is because I am reading the same file again in another program ad there this \n is causing the error.

0

There are 0 best solutions below