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. Cannot parse Json data

Cannot parse Json data

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.7k Views
  • 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.
  • D Offline
    D Offline
    dridk
    wrote on last edited by
    #1

    This is strange! I cannot parse a simple json data in one line !

    @#include <QCoreApplication>
    #include <QByteArray>
    #include <QDebug>
    #include <QJsonDocument>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QString data= "{'users': [{'id': 1,'name': 'Joe', 'email': 'joe@places.com'},{ 'id': 2,'name': 'Joe2','email': 'joe@places.com'}]}";
    
    QJsonParseError * error = new QJsonParseError;
    QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8(), error);
    
    qDebug()<<doc.toJson();
    qDebug()<<error->errorString();
    
    
    return a.exec&#40;&#41;;
    

    }
    @

    This code return me "unterminated object"... I submitted it as a bug.. But I may be wrong.. Do you know why ?

    Nothing in Biology Makes Sense Except in the Light of Evolution

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

      Hi,

      Your JSON is invalid, you need to use double quotes not single

      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
      0
      • D Offline
        D Offline
        dridk
        wrote on last edited by
        #3

        Ah okay ! I was confusing because this json was working on http://jsonviewer.stack.hu/ !

        Nothing in Biology Makes Sense Except in the Light of Evolution

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

          They might be a bit less picky on the format

          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
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            According to the "JSON specs":http://json.org/ (emphasis added),[quote]A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.[/quote]http://jsonviewer.stack.hu/ is using non-standard extensions, which other parsers are not guaranteed to provide.

            Here is a site which checks if your JSON string is valid or not: http://jsonlint.com/ (I pasted your data into JSON Lint and it failed the test)

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            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