print json file without \n character
-
I have this Json file:
{
"place": {
"id": "99"
},
"camera": {
"id": "99",
"url": "http://192.168.0.250/stuff.php?",
}
}What i get is all the content printed in one line with character \n printed after each field and not as it is in the file. This happens on my Ubuntu machine, but not in another machine with Debian. I'd like the file content printed line by line.. any hints? I use this code to print the content of a Json file:
QString val;
QFile file;
file.setFileName("../config.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
val = file.readAll();
file.close();
qWarning() << val; -
Hi and welcome to devnet,
In that case use a while loop and read your file line by line. For that you can use QTextStream::readLine for example.
-
@rokk Try printing this way.
https://forum.qt.io/topic/67573/parsing-json-returned-from-web-request/2
Look forqDebug()
-
@p3c0 it works using noquote() but this function was introduced in Qt 5.4 so it will not work in prior versions.. so my question is, has the behaviour (escaping non printable characters) of qWarning() changed recently? I cannot understand why in my system (Ubuntu 16 - Qt 5.7) it doesn't work, but works in other Debian system I have with Qt 5.3...
-
so my question is, has the behaviour (escaping non printable characters) of qWarning() changed recently.
Perhaps since Qt 5.4 when they introduced
noquote
forQDebug
. Not sure.I cannot understand why in my system (Ubuntu 16 - Qt 5.7) it doesn't work, but works in other Debian system I have with Qt 5.3...
It works on Ubuntu 14 with Qt 5.7.
In Qt 5.3 I think it worked because the non printable characters were not escaped by default. -
@rockk yes it has changed. One of the reason being to avoid people getting "wrong output" when invisible control characters were part of the strings outputted.