Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. print json file without \n character
Forum Updated to NodeBB v4.3 + New Features

print json file without \n character

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rokk
    wrote on last edited by
    #1

    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;

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        @rokk Try printing this way.
        https://forum.qt.io/topic/67573/parsing-json-returned-from-web-request/2
        Look for qDebug()

        157

        R 1 Reply Last reply
        1
        • p3c0P p3c0

          @rokk Try printing this way.
          https://forum.qt.io/topic/67573/parsing-json-returned-from-web-request/2
          Look for qDebug()

          R Offline
          R Offline
          rokk
          wrote on last edited by
          #4

          @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...

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @rokk

            so my question is, has the behaviour (escaping non printable characters) of qWarning() changed recently.

            Perhaps since Qt 5.4 when they introduced noquote for QDebug. 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.

            157

            R 1 Reply Last reply
            3
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • p3c0P p3c0

                @rokk

                so my question is, has the behaviour (escaping non printable characters) of qWarning() changed recently.

                Perhaps since Qt 5.4 when they introduced noquote for QDebug. 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.

                R Offline
                R Offline
                rokk
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved