I'm currently reading in a json file to a QJsonDocument and then converting it to a QString such that it looks like:
"thing1":"thing1value",
"thing2":"thing2,value",
"thing3":"thing3value",
Each line ends with a comma and I would like to try and format it a bit to show to the user without the quotations and a new line after each line. I was attempting use the replace function to replace any commas with a new line. The problem is that just using the replace function to replace all commas with
also means that anything inside the quotes is altered too like:
"thing2":"thing2
value"
Is there any easy way to alter the values exterior of quotes without touching the insides? Is there perhaps a better approach to the overall formatting I could be doing instead? I have a feeling this is asking a bit much of Qt and I may just have to write some function that indexOf finds the first quote and tracks it to the next etc.
Here's what I have so far essentially
QString jDoc = file.readAll();
file.close();
QJsonParseError parserError;
QJsonDocument jsonInit = QJsonDocument::fromJson(jDoc.toUtf8(), &parserError);
qDebug() << parserError.errorString();
QString strJson(jsonInit.toJson(QJsonDocument::Indented));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…