GithubHelp home page GithubHelp logo

flavio / qjson Goto Github PK

View Code? Open in Web Editor NEW
286.0 286.0 140.0 672 KB

QJson is a qt-based library that maps JSON data to QVariant objects.

Home Page: http://qjson.sourceforge.net

License: GNU Lesser General Public License v2.1

CMake 4.34% C++ 91.89% C 0.59% Yacc 3.18%

qjson's People

Contributors

agateau avatar alediaferia avatar anluoma avatar dant3 avatar dfaure avatar drizt avatar flavio avatar gooseensky avatar gregschlom avatar h57624paen avatar hotgloupi avatar jkjuopperi avatar krop avatar mathieu avatar maxdesiatov avatar microe avatar milianw avatar moio avatar niclasr avatar panicking avatar patdowney avatar petrows avatar rakuco avatar reavertm avatar rudilee avatar shybovycha avatar svuorela avatar vestnik avatar zgyarmati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qjson's Issues

Unsafe pointer use in Serializer::serialize()

In Serializer::serialize( const QVariant &v, bool *ok) a pointer
to the local variable _ok is used after it has gone out of scope:

  if (ok) {
    *ok = true;
  } else {
    bool _ok = true;
    ok = &_ok;
  }

  return d->serialize(v, ok);

Can't build testscanner.exe on Windows

I got this errors

CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x6428): undefined reference to `JSonScanner::JSonScanner(QIODevice*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x64a7): undefined reference to `JSonScanner::yylex(QVariant*, yy::location*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x6536): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x6565): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x6733): undefined reference to `JSonScanner::JSonScanner(QIODevice*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x674f): undefined reference to `JSonScanner::allowSpecialNumbers(bool)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x67ce): undefined reference to `JSonScanner::yylex(QVariant*, yy::location*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x67f2): undefined reference to `JSonScanner::yylex(QVariant*, yy::location*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x6e76): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x7149): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x73e3): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x7661): undefined reference to `JSonScanner::JSonScanner(QIODevice*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x7676): undefined reference to `JSonScanner::allowSpecialNumbers(bool)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x76f5): undefined reference to `JSonScanner::yylex(QVariant*, yy::location*)'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x77d0): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x7b53): undefined reference to `JSonScanner::~JSonScanner()'
CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj):testscanner.cpp:(.text+0x7b84): undefined reference to `JSonScanner::~JSonScanner()'
C:/Qt/Qt5.3.1/Tools/mingw482_32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\testscanner.dir/objects.a(testscanner.cpp.obj): bad reloc address 0x4 in section `.data'

Problem in JsonScanner class. It's internal class which hasn't QJSON_EXPORT. Windows requires some special attributes for classes/functions in shared libs. So JsonScanner must be defined with QJSON_EXPORT or testscanner must be linked against ./src/CMakeFiles/qjson.dir/json_scanner.cpp.obj.

Build with qt 5.0.1

I just upgraded to QT 5.0.1 and trying to re-build qjson. But I get the error below, can we not build it yet with qt 5?

CMake 2.8 , QT 5.0.1 MingGW 4.7 Windows 7 x64

-----output----
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindQt4.
cmake:1216 (message):
Found unsuitable Qt version "5.0.1" from
C:/Qt/Qt5.0.1/5.0.1/mingw47_32/bin/qmake.exe, this code requires Qt 4.x
Call Stack (most recent call first):
CMakeLists.txt:35 (FIND_PACKAGE)

'_strtoui64' was not declared in this scope

Hello. I can't build the latest (e03265e) qjson with Windows 7 64-bit, Qt-4.8.4 and MinGW.


c:\build\qjson>mingw32-make VERBOSE=1
C:\CMake\bin\cmake.exe -HC:\build\qjson -BC:\build\qjson --check-build-system CM
akeFiles\Makefile.cmake 0
C:\CMake\bin\cmake.exe -E cmake_progress_start C:\build\qjson\CMakeFiles C:\buil
d\qjson\CMakeFiles\progress.marks
mingw32-make -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory `c:/build/qjson'
mingw32-make -f src\CMakeFiles\qjson.dir\build.make src/CMakeFiles/qjson.dir/dep
end
mingw32-make[2]: Entering directorc:\build\qjson>mingw32-make VERBOSE=1
C:\CMake\bin\cmake.exe -HC:\build\qjson -BC:\build\qjson --check-build-system CM
akeFiles\Makefile.cmake 0
C:\CMake\bin\cmake.exe -E cmake_progress_start C:\build\qjson\CMakeFiles C:\buil
d\qjson\CMakeFiles\progress.marks
mingw32-make -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory `c:/build/qjson'
mingw32-make -f src\CMakeFiles\qjson.dir\build.make src/CMakeFiles/qjson.dir/dep
end
mingw32-make[2]: Entering directory `c:/build/qjson'
C:\CMake\bin\cmake.exe -E cmake_depends "MinGW Makefiles" C:\build\qjson C:\buil
d\qjson\src C:\build\qjson C:\build\qjson\src C:\build\qjson\src\CMakeFiles\qjso
n.dir\DependInfo.cmake --color=
mingw32-make[2]: Leaving directory `c:/build/qjson'
mingw32-make -f src\CMakeFiles\qjson.dir\build.make src/CMakeFiles/qjson.dir/bui
ld
mingw32-make[2]: Entering directory `c:/build/qjson'
C:\CMake\bin\cmake.exe -E cmake_progress_report C:\build\qjson\CMakeFiles 5
[ 9%] Building CXX object src/CMakeFiles/qjson.dir/json_scanner.cpp.obj
cd /d C:\build\qjson\src && C:\QtSDK\mingw\bin\g++.exe -DQJSON_MAKEDLL -DQT_CO
RE_LIB -DQT_DLL -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_
TO_ASCII @CMakeFiles/qjson.dir/includes_CXX.rsp -o CMakeFiles\qjson.dir\json_s
canner.cpp.obj -c C:\build\qjson\src\json_scanner.cpp
In file included from C:\build\qjson\src\json_scanner.cpp:21:
json_scanner.yy: In member function 'virtual int JSonScanner::yylex()':
json_scanner.yy:84: error: '_strtoui64' was not declared in this scope
In file included from C:\build\qjson\src\json_scanner.cpp:21:
json_scanner.yy:95: error: '_strtoi64' was not declared in this scope
mingw32-make[2]: *** [src/CMakeFiles/qjson.dir/json_scanner.cpp.obj] Error 1
mingw32-make[2]: Leaving directory `c:/build/qjson'
mingw32-make[1]: *** [src/CMakeFiles/qjson.dir/all] Error 2
mingw32-make[1]: Leaving directory `c:/build/qjson'
mingw32-make: *** [all] Error 2y `c:/build/qjson'
C:\CMake\bin\cmake.exe -E cmake_depends "MinGW Makefiles" C:\build\qjson C:\buil
d\qjson\src C:\build\qjson C:\build\qjson\src C:\build\qjson\src\CMakeFiles\qjso
n.dir\DependInfo.cmake --color=
mingw32-make[2]: Leaving directory `c:/build/qjson'
mingw32-make -f src\CMakeFiles\qjson.dir\build.make src/CMakeFiles/qjson.dir/bui
ld
mingw32-make[2]: Entering directory `c:/build/qjson'
C:\CMake\bin\cmake.exe -E cmake_progress_report C:\build\qjson\CMakeFiles 5
[ 9%] Building CXX object src/CMakeFiles/qjson.dir/json_scanner.cpp.obj
cd /d C:\build\qjson\src && C:\QtSDK\mingw\bin\g++.exe -DQJSON_MAKEDLL -DQT_CO
RE_LIB -DQT_DLL -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_
TO_ASCII @CMakeFiles/qjson.dir/includes_CXX.rsp -o CMakeFiles\qjson.dir\json_s
canner.cpp.obj -c C:\build\qjson\src\json_scanner.cpp
In file included from C:\build\qjson\src\json_scanner.cpp:21:
json_scanner.yy: In member function 'virtual int JSonScanner::yylex()':
json_scanner.yy:84: error: '_strtoui64' was not declared in this scope
In file included from C:\build\qjson\src\json_scanner.cpp:21:
json_scanner.yy:95: error: '_strtoi64' was not declared in this scope
mingw32-make[2]: *** [src/CMakeFiles/qjson.dir/json_scanner.cpp.obj] Error 1
mingw32-make[2]: Leaving directory `c:/build/qjson'
mingw32-make[1]: *** [src/CMakeFiles/qjson.dir/all] Error 2
mingw32-make[1]: Leaving directory `c:/build/qjson'
mingw32-make: *** [all] Error 2

QJson and QProperty

Hi Flavio,

Thanks for your genius lib, great job, very powerful.

I'm trying to use your QJson library to parse content from D3 Api. I use QProperty to initialize my objects.
It worked fine with standard value as int, QString, QDate, but how can use QList?

Example :

QJson from D3 Api :

{
"heroes" : [ {
"name" : "Toto",
"id" : 3
}, {
"name" : "Toto2",
"id" : 4
} ],
"lastHeroPlayed" : 3
}

My Class :

class D3_Heroe : public QObject
{
Q_Object
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(int id READ getID WRITE setID)
...
}

class D3_Career : public QObject
{
Q_Object
Q_PROPERTY(QList<D3_Heroe> hereos READ getHeroes WRITE setHeroes)
Q_PROPERTY(QString lastHeroPlayed READ getlastHeroPlayed WRITE setlastHeroPlayed)
...
}

Using your QJson::QObjectHelper :

// _pReply is a QNetworkReply coming from D3_API
QVariant res = parser.parse( _pReply->readAll(), &bOk );
D3_Career pCareer = new D3_Career();
QJson::QObjectHelper::qvariant2qobject( res.toMap(), pCareer );

Any ideas?

Regards,
Jรฉrรฉmie

qjsonDebug() slows the parsing down

json_parser.yy, json_scanner.cpp and json_parser.cc have qjsonDebug() << ... printouts enabled by default.
Even though qjsonDebug() ignores this output, printing is still done in the enclosing code, therefore slowing it down.
qjsonDebug() should be #ifndef-ed with some preprocessor variable.

PS: Even after with this fix qjson parser is still significantly slower than Qt5 internal parer.

serialize QVariant()

Hello,

Two big problems about the library:

  • First: serialize a QVariant() return NULL, why? It's not convenient at all to use that in an app afterwards.
  • Second: I quote from the doc "If the returned string is empty, the document was empty." I don't get that at all ! An empty string is not json...

Building on Windows fails, missing xlocale.h

I am building QJson with MSVC 2010 and I get the following error:

c:\projects\qjson\src\json_scanner.h:37: error: C1083: Cannot open include file: 'xlocale.h': No such file or directory

However there is a header called xlocale, so I changed the include. But then it complains that there are no symbols "locale_t" and "newlocale". Is it supposed to build with Microsoft compilers at all?

Double parsing broken ?

Hi,

I can't get the double parsing to work :

QByteArray array = "{ "name" : 0.9 }";
QJson::Parser parser;
qDebug() << parser.parse(array);

Results in :
QVariant(QVariantMap, QMap(("name", QVariant(double, 0) ) ) )

Expected :
QVariant(QVariantMap, QMap(("name", QVariant(double, 0.9) ) ) )

Related unit tests are also failing (at least on my OS : Mac OS X)

[Tested in branches, master and 1_0_0]
[Using clang++ and Qt5 (5.0.0)]

Am i missing something ?
Can it be related to this commit 453ce33 ?

Thanks;

JSON Indentation bug in list

Hi,

There is some indentation problems using full indentation mode with list.
Here is an example of the content that is generated by qjson (note that i give all because i don't know which part is generating the bug):

HINT: Search for "columns" / "constraints" list and see blank lines and unindented values.
"references" looks to have it's opening bracket very far : "references" : {

{
 "connection" :  {
  "connectOptions" : "",
  "connectionName" : "my connection",
  "databaseName" : "/ramdisk/db.sqlite",
  "driverName" : "QSQLITE",
  "hostName" : "",
  "numericalPrecisionPolicy" : -1,
  "password" : "XXXXXXXXX",
  "port" : -1,
  "userName" : ""
 },
 "schemas" : [
  {
   "isForeignKeyEnabled" : true,
   "revision" : "2013-07-21T00:00:00Z",
   "tables" : [
    {
     "columns" : [
      {
       "constraints" : [
        {
         "collationName" : "",
         "conflictClause" : "",
         "defaultValue" : null,
         "expression" : "",
         "name" : "artists_id_pk",
         "references" :          {
          "columns" : [

          ],
          "tableName" : ""
         },
         "sortOrder" : -1,
         "type" : 257
        }
       ],
       "name" : "id",
       "type" : 4
      },
      {
       "constraints" : [
        {
         "collationName" : "",
         "conflictClause" : "",
         "defaultValue" : null,
         "expression" : "",
         "name" : "artists_first_name_index",
         "references" :          {
          "columns" : [

          ],
          "tableName" : ""
         },
         "sortOrder" : -1,
         "type" : 128
        },
        {
         "collationName" : "",
         "conflictClause" : "",
         "defaultValue" : null,
         "expression" : "",
         "name" : "artists_first_name_not_null",
         "references" :          {
          "columns" : [

          ],
          "tableName" : ""
         },
         "sortOrder" : -1,
         "type" : 2
        }
       ],
       "name" : "first_name",
       "type" : 10
      },
      {
       "constraints" : [
        {
         "collationName" : "",
         "conflictClause" : "",
         "defaultValue" : null,
         "expression" : "",
         "name" : "artists_last_name_index",
         "references" :          {
          "columns" : [

          ],
          "tableName" : ""
         },
         "sortOrder" : -1,
         "type" : 128
        },
        {
         "collationName" : "",
         "conflictClause" : "",
         "defaultValue" : null,
         "expression" : "",
         "name" : "artists_last_name_not_null",
         "references" :          {
          "columns" : [

          ],
          "tableName" : ""
         },
         "sortOrder" : -1,
         "type" : 2
        }
       ],
       "name" : "last_name",
       "type" : 10
      },
      {
       "constraints" : [

       ],
       "name" : "birthday",
       "type" : 16
      },
      {
       "constraints" : [

       ],
       "name" : "scene_name",
       "type" : 10
      }
     ],
     "constraints" : [
      {
       "columns" : [
"birthday"
       ],
       "conflictClause" : "",
       "expression" : "",
       "name" : "artists_birthday_index",
       "references" :        {
        "columns" : [

        ],
        "tableName" : ""
       },
       "sortOrder" : -1,
       "type" : 128
      },
      {
       "columns" : [
"scene_name"
       ],
       "conflictClause" : "",
       "expression" : "",
       "name" : "artists_scene_name_index",
       "references" :        {
        "columns" : [

        ],
        "tableName" : ""
       },
       "sortOrder" : -1,
       "type" : 128
      }
     ],
     "name" : "artists"
    }
   ]
  }
 ]
}

Windows debug library

Hi.

On Windows debug library should have 'd' postfix. Add this to CMakeLists.txt

if (WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
endif (WIN32)

allowSpecialNumbers is broken in some cases

Parsing a simple [Infinity] works fine, but a more complex { "inf": Infinity } fails

void TestParser::testReadSpecialNumbers() {
    QFETCH(QByteArray, json);
    Parser parser;
    parser.allowSpecialNumbers(true);

    bool ok= false;

    parser.parse(json, &ok);

    QVERIFY(ok);

}

void TestParser::testReadSpecialNumbers_data() {
    QTest::addColumn<QByteArray>("json");

    QTest::newRow("Infinity") << QByteArray("{ \"inf\": Infinity }");
    QTest::newRow("-Infinity") << QByteArray("{ \"inf\": -Infinity }");
    QTest::newRow("NaN") << QByteArray("{ \"nan\": NaN }");
}

This btw worked with a year old QJson.

It is the handling of <ALLOW_SPECIAL_NUMBERS>{ in json_scanner.yy that is somehow broken. Removing the condition in the yy file kind of gives a local fix, but it allows special numbers everywhere.

CMake: Qt 5 checker

It looks like your checks of Qt 5 are wrong: I tried to build it and got Qt5 not found, searching for Qt4, anyway, I have Qt 5 on my PC and I have built my Qt 5 projects.

Can't build testscanner.exe on Linux

This is exactly #63 except that for Linux. I just removed the WIN32 stanzas in the patch that solved the aforementioned issue and it worked.

Considering the patch I think this is actually a bug while building shared libraries.

qjson should have an option to control the width of the tab used for indent

Currently, the qjson serializer's indentation tuning and more precisely the full indent mode (QJson::IndentFull) supports tab width of 1 space character. The documentation states:
full :

{             
 "foo" : 0,   
 "foo1" : 1,  
 "foo2" : [   
  {           
   "foo3" : 3,
   "foo4" : 4 
  }           
 ]            
}

It would be great if qjson serializer has the following set of getter + setter:

  • int tabWidth() const;
  • void setTabWidth( const int inTabWidth );

... or tabSize or indentTab{Width, Size}.

Qt5 introduced QJsonDocument class that provides JSON translation services.

Here is a sample code that illustrates the desired additional behavior and compares qjson and Qt5 QJsonDocument behavior:

    QVariantMap top;
    top.insert( "0", QString( "first" ) );
    top.insert( "1", QString( "second" ) );
    top.insert( "2", QString( "third" ) );

    QVariantList vl;
    vl << QString( "variantList0" ) << QString( "variantList1" ) << QString( "variantList2" );
    top.insert( "variantList", vl );

    QByteArray converted;
    bool ok = false;
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
    const QJsonDocument doc = QJsonDocument::fromVariant( top );
    ok = true;
    converted = doc.toJson();
#else
    QJson::Serializer serializer;
    serializer.setIndentMode( QJson::IndentFull );
    converted = serializer.serialize( top, &ok );
#endif
    qDebug() << "test:" << endl << converted;

The output for Qt5 QJsonDocument way is:

test:
"{
    "0": "first",
    "1": "second",
    "2": "third",
    "variantList": [
        "variantList0",
        "variantList1",
        "variantList2"
    ]
}
"

... and qjson's output:

test:
"{
 "0" : "first",
 "1" : "second",
 "2" : "third",
 "variantList" : [
"variantList0",
"variantList1",
"variantList2"
 ]
}"

Make a Qt5 compatible release

Master is running fine for me with Qt5 for a long time now but as software that depends on QJson now is doing releases with Qt5 support, it would be very helpful to have a QJson release with Qt5 support too.

resp->end(data) never write data

Hello,

in the function QHttpResponse::end(...) the flag m_finished is true, just before write(data).
So write(data) exit without sending data!

Best regards

Andrea

BlackBerry 10 support

Hi !

I know that qjson is not officially supported on BlackBerry 10 but I really wanted to give it a try and here is where the compiler complains :

../src/network/qjson/serializer.cpp:230:31: error: expected unqualified-id before '(' token
../src/network/qjson/serializer.cpp:239:18: error: expected unqualified-id before '(' token

Thanks

Linking problem: relocation R_X86_64_PC32 against symbol `_ZN5QJson13ParserPrivateC1Ev'

HI,

I'm trying to build your library with ubuntu-sdk package on Ubuntu 13.04 x64
I'm doing in qjson folder:

    cmake -G "Unix Makefiles"
    make

I'm getting this error:

    Linking CXX shared library ../lib/libqjson.so
    /usr/bin/ld: CMakeFiles/qjson.dir/parser.cpp.o: relocation R_X86_64_PC32 against symbol `_ZN5QJson13ParserPrivateC1Ev' can not be used when making a shared object; recompile with -fPIC

Android build error with isinf function

I tried to build QJson for android with android-cmake and android-ndk-r10c.

cd /home/taurus/develop/qjson/build/src && /home/taurus/android/toolchain/bin/arm-linux-androideabi-g++ -DANDROID -DQJSON_MAKEDLL -DQT_CORE_LIB -DQT_NO_DEBUG -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5__ --sysroot=/home/taurus/android/toolchain/sysroot -fsigned-char -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fdata-sections -ffunction-sections -fPIC -Wno-psabi -frtti -fexceptions -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -fPIC -I/home/taurus/develop/qjson/build/src -I/home/taurus/develop/qjson/src -isystem /home/taurus/android/toolchain/sysroot/usr/include -I/home/taurus/android/Qt5.3.2/5.3/android_armv7/include -I/home/taurus/android/Qt5.3.2/5.3/android_armv7/include/QtCore -I/home/taurus/android/Qt5.3.2/5.3/android_armv7/mkspecs/android-g++ -I/home/taurus/develop/qjson/src/. -o CMakeFiles/qjson.dir/serializer.cpp.o -c /home/taurus/develop/qjson/src/serializer.cpp /home/taurus/develop/qjson/src/serializer.cpp: In member function 'QByteArray QJson::Serializer::SerializerPrivate::serialize(const QVariant&, bool*, int)': **/home/taurus/develop/qjson/src/serializer.cpp:258:55: error: 'isinf' was not declared in this scope** /home/taurus/develop/qjson/src/serializer.cpp:258:55: note: suggested alternative: /home/taurus/android/toolchain/bin/../lib/gcc/../../include/c++/4.6/cmath:753:5: note: 'std::isinf'

It can be easy fixed if replace isinf with std::isinf. I not sure that is a right way. I looked at git history. commit Make it build on Android

New release

Do you have plans to make a new release? Many time passed from last one. So it will be nice to have a new version.

Encode String not behaving well with special characters.

In encodeString() chars are checked using

if(ch.unicode() >= 32 && ch.unicode() < 128) 

If they are not within this range, some specific treatment for special characters with a switch/case are made.
Problems is that some of those special characters are within the first checked range, and so they don't get treated correctly.

Problem exists for ", / and \

Encoding following String "Hello "Mister" " will encode to "Hello "Mister" " instead of "Hello "Mister" "

Attached a suggested implementation.

Thanks again for the very usefull lib!!

qjson.zip

QJson does not escape control characters when sanitizing strings

As per RFC 4627, section 2.5, control characters must be escaped when encoding strings in JSON documents:

All Unicode characters may be placed within the
quotation marks except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F).

Serializer::SerializerPrivate::sanitizeString escapes all characters >= 128, backslashes, quotes, tabs and new lines but not control characters.

Include broken / unkown type

Hi,

first, thanks for you work, it helped me a lot!

I use VS2010 on Win7. In the current version the include #include <xlocale.h> causes an include error - it works without the .h

Still, with the fixed include one will get an compiler error since the type "locale_t" is unknown.

B.r.
Michael

Performance issue

Parsing my json-files is very slow, especially compared to jackson (Java). The files look basically all the same (I attached only the biggest one), mainly a long list of short lists containing ints.

8 different but similar files (~150-220KB) were parsed two times in a row in one process.

Results of QJSON as packaged in Debian (unstable):

Parsed "Hard Times-20101226190115" in 483 ms
Parsed "increaseEasy220-20101109222554" in 352 ms
Parsed "increaseEasy220-20101129222827" in 351 ms
Parsed "increaseEasy220-20110116103323" in 380 ms
Parsed "Interrupted-20110109183721" in 473 ms
Parsed "training3-20101023171040" in 476 ms
Parsed "training4-20101025182142" in 442 ms
Parsed "training4-20101125221838" in 432 ms

---
Parsed "Hard Times-20101226190115" in 492 ms
Parsed "increaseEasy220-20101109222554" in 360 ms
Parsed "increaseEasy220-20101129222827" in 357 ms
Parsed "increaseEasy220-20110116103323" in 383 ms
Parsed "Interrupted-20110109183721" in 481 ms
Parsed "training3-20101023171040" in 481 ms
Parsed "training4-20101025182142" in 442 ms
Parsed "training4-20101125221838" in 430 ms

Results of QJSON from git (using -DCMAKE_BUILD_TYPE=Release):

Parsed "Hard Times-20101226190115" in 477 ms
Parsed "increaseEasy220-20101109222554" in 345 ms
Parsed "increaseEasy220-20101129222827" in 347 ms
Parsed "increaseEasy220-20110116103323" in 371 ms
Parsed "Interrupted-20110109183721" in 472 ms
Parsed "training3-20101023171040" in 463 ms
Parsed "training4-20101025182142" in 427 ms
Parsed "training4-20101125221838" in 420 ms

---
Parsed "Hard Times-20101226190115" in 480 ms
Parsed "increaseEasy220-20101109222554" in 345 ms
Parsed "increaseEasy220-20101129222827" in 345 ms
Parsed "increaseEasy220-20110116103323" in 371 ms
Parsed "Interrupted-20110109183721" in 466 ms
Parsed "training3-20101023171040" in 464 ms
Parsed "training4-20101025182142" in 423 ms
Parsed "training4-20101125221838" in 416 ms

Jackson:

Parsed Hard Times-20101226190115 in 426ms
Parsed increaseEasy220-20101109222554 in 122ms
Parsed increaseEasy220-20101129222827 in 63ms
Parsed increaseEasy220-20110116103323 in 12ms
Parsed Interrupted-20110109183721 in 9ms
Parsed training3-20101023171040 in 10ms
Parsed training4-20101025182142 in 9ms
Parsed training4-20101125221838 in 7ms

---
Parsed Hard Times-20101226190115 in 11ms
Parsed increaseEasy220-20101109222554 in 6ms
Parsed increaseEasy220-20101129222827 in 7ms
Parsed increaseEasy220-20110116103323 in 6ms
Parsed Interrupted-20110109183721 in 8ms
Parsed training3-20101023171040 in 10ms
Parsed training4-20101025182142 in 8ms
Parsed training4-20101125221838 in 7ms

C++-Code:

QTime lTimer;
QJson::Parser lParser;

QString lFiles[] = {
  "Hard Times-20101226190115",
  "increaseEasy220-20101109222554",
  "increaseEasy220-20101129222827",
  "increaseEasy220-20110116103323",
  "Interrupted-20110109183721",
  "training3-20101023171040",
  "training4-20101025182142",
  "training4-20101125221838"
};

for (int k = 0; k < 2; ++k) {
  for (uint i = 0; i < sizeof(lFiles) / sizeof(QString); ++i) {
    QFile lFile(QString(lFiles[i]));
    lTimer.start();
    QVariant lResult = lParser.parse(&lFile, &lOk);
    int lDuration = lTimer.elapsed();
    qDebug() << "Parsed " << lFiles[i] << " in " << lDuration << "ms";
  }
  qDebug() << "---";
}

Java-Code:

String[] lFiles = {
  "Hard Times-20101226190115",
  "increaseEasy220-20101109222554",
  "increaseEasy220-20101129222827",
  "increaseEasy220-20110116103323",
  "Interrupted-20110109183721",
  "training3-20101023171040",
  "training4-20101025182142",
  "training4-20101125221838"
};

for (int k = 0; k < 2; ++k) {
  for (int i = 0; i < lFiles.length; ++i) {
    ObjectMapper mapper = new ObjectMapper();
    long lStarttime = System.currentTimeMillis();
    JsonNode lRootNode = (JsonNode) mapper.readValue(new File(lFiles[i]), JsonNode.class);
    long lEndtime = System.currentTimeMillis();
    System.out.println("Parsed " + lFiles[i] + " in " + (lEndtime - lStarttime) + "ms");
  }
  System.out.println("---");
}

File used to reproduce the issue.

Error compiling with Mingw 64

I'm trying to compile qjson using the mingw64 provided by the msys2 [1] and mingw64 (gcc version 6.1.0 (Rev1, Built by MSYS2 project) [2].

I'm using the latest updates from git.

Using cmake or cmake-gui, configure and generate runs ok, with these messages in output:

Qt5 found (in red)
Enable QStringBuilder (in red)
Configuring done
Generating done

Now, in the console of msys2:

cd build
mingw32-make.exe

Some error occurs in the compilation, time, like these lines copied from console:

Tiedtke@Tiedtke-PC MINGW64 ~/dev/qjson/build
$ mingw32-make.exe
[ 11%] Building CXX object src/CMakeFiles/qjson-qt5.dir/parser.cpp.obj
[ 22%] Building CXX object src/CMakeFiles/qjson-qt5.dir/qobjecthelper.cpp.obj
[ 33%] Building CXX object src/CMakeFiles/qjson-qt5.dir/json_scanner.cpp.obj
[ 44%] Building CXX object src/CMakeFiles/qjson-qt5.dir/json_parser.cc.obj
[ 55%] Building CXX object src/CMakeFiles/qjson-qt5.dir/parserrunnable.cpp.obj
[ 66%] Building CXX object src/CMakeFiles/qjson-qt5.dir/serializer.cpp.obj
[ 77%] Building CXX object src/CMakeFiles/qjson-qt5.dir/serializerrunnable.cpp.obj
mingw32-make[2]: *** No rule to make target 'src/qjson-qt5_autogen.cpp', needed by 'src/CMakeFiles/qjson-qt5.dir/qjson-qt5_autogen.cpp.obj'. Stop.
CMakeFiles\Makefile2:117: recipe for target 'src/CMakeFiles/qjson-qt5.dir/all' failed
mingw32-make[1]: *** [src/CMakeFiles/qjson-qt5.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

Searching the file: qjson-qt5_autogen.cpp I verified that it not exists or was not generated.

There are some tips for use in mingw64 that I forgot?

Thanks on advance!

Best Regards.

Thiago Tiedtke dos Reis

[1] https://msys2.github.io/
[2] https://github.com/Alexpux/MINGW-packages and https://github.com/Alexpux/MSYS2-packages

Wrong indents when serialization of string in arrays

expected

{ "foo" : 0, "foo1" : 1, "foo2" : [
  { "bar" : 1, "foo" : 0, "foobar" : 0 },
  { "bar" : 1, "foo" : 1, "foobar" : 1 }
 ], "foo3" : [
  1,
  2,
  3,
  4,
  5,
  6
 ]
 "foobaz" : [
  "one",
  "two",
  "three",
  "four"
 ] }

real

{ "foo" : 0, "foo1" : 1, "foo2" : [
  { "bar" : 1, "foo" : 0, "foobar" : 0 },
  { "bar" : 1, "foo" : 1, "foobar" : 1 }
 ], "foo3" : [
  1,
  2,
  3,
  4,
  5,
  6
 ], "foobaz" : [
"one",
"two",
"three",
"four"
 ] }

Qt5Cored.dll

When I build qjson with the "The CLI way" the libqjson.dll requires the debug version of Qt5Core (Qt5Cored.dll)

Qt5Cored.dll is 72 MB vs Qt5Core.dll is 4 MB

QT 5.0.1
Cmake 2.8
Windows 7 x64

Cannot build with Qt version < 4.4

I can't compile qjson with Qt 4.2.1, there is no QT_BEGIN_NAMESPACE and QT_END_NAMESPACE macros and no QRunnable interface which is according to Qt's doc introduced in Qt 4.4, perhaps the Qt version requirement in the README need to be corrected to "Qt 4.4 or greater"?

Request for Qt 5 release

Hi,

Homebrew maintainer here.

Just a heads up that this project has now been "boneyarded" in Homebrew due to lack of Qt 5 support in a tagged release. This means that qjson was moved from https://github.com/Homebrew/homebrew-core to https://github.com/Homebrew/homebrew-boneyard, and has effectively been removed from Homebrew for all intents and purposes.

My understanding is that the qjson master branch does actually have Qt 5 support, so we could reinstate qjson in Homebrew if a new version tag with Qt 5 support could be pushed to GitHub.

Thanks for your help and please let us know if you have any questions.

Problem when trying to parse simple Json

When I trying to simple Json I go message "Error: syntax error, unexpected invalid. Line 4" (Qt 5.1.1, Mingw, Win 7 x64)

Json:

{
"fields" : [
{
"index" : 2,
"name" : "category_weight",
"type" : 2
},
{
"index" : 0,
"name" : "category_id",
"type" : 2
},
{
"index" : 1,
"name" : "category_name",
"type" : 10
}
]
}

Cannot be builded with qt-namespaces

You use forward qt classes declarations like:
class QIODevice;
class QVariant;

And it doesn't let me use qt-namespaces without changing your code.

VS2012 - undefined symbols strtoll and strtoull

While trying to build the library with Visual Studio 2012 encountered:

  • unknown symbols strtoll and strtoull

Can be fixed with a simple workaround;

ifdef _WIN32

define strtoll _strtoi64

define strtoull _strtoui64

endif

in json_scanner,cc , but since this file is auto-generated from bison grammar (AFAIU) - there should be some more smooth fix for it.

QDateTime UTC are not converted / restored correctly.

I'm wanting to save / restore QDateTime being UTC and it fails.

I opened a Qt bug for that, but it looks like they disagree being a Qt bug, QVariant being converted in ISO date, loosing milliseconds.

https://bugreports.qt-project.org/browse/QTBUG-30250

Is there something you can do, or i will be borrow to just specialized format each time i would like to save datetime with utc ?

Example of code i currently use:


d->revision initialized with: QDateTime::currentDateTimeUtc()

QVariant DatabaseSchema::toVariant() const
{
    QVariantMap map;

    map[ "revision" ] = d->revision;

    return map;
}

void DatabaseSchema::fromVariant( const QVariant& variant )
{
    const QVariantMap map = variant.toMap();

    d->revision = map.value( "revision" ).toDateTime();
}

toVariant is written in a file, then read back and set in a new objet using fromVariant()

CMake config depends on qtgui, while the library actually doesn't need it

CMake error message when qtgui is not installed on the build system:

CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Qt4 (missing: QT_UIC_EXECUTABLE) (found suitable version
  "4.8.7", minimum required is "4.5")

PR with a fix follows soon

considers empty file as valid

An empty file or empty QByteArray gets parsed as valid json.

According to json specs, a piece of json needs to have an object or an array.

Adding a line like

QTest::newRow("no data") << QByteArray("");

to

void TestParser::parseInvalidObject_data() 

makes the test fail. I would expect it to pass.

Not installable in parallel for Qt4+5

QJson always compiles to the same "name" for Qt4 and Qt5 so that only one of both versions is available. As probably not all software will be able to move of Qt4 immediately, it would be helpful to have QJson installed in parallel for Qt4 and Qt5.

Common practice seems to be to give the Qt5 version a 5 in their name when being installed, e.g. libq5json.so/Q5JSONConfig.cmake/...

UTF8 QString parse problem

If i try to parse some UTF8 JSON with russian characters in value part of json expression, then I get in result QString from QVariant with many '?' characters chr(63).

Parsing from QIODevice fails.

Network reply was finished without errors and has valid json.

auto reply = qobject_cast<QNetworkReply*> (sender ());
const auto& data = QJson::Parser ().parse (reply);

data is invalid variant, and in logs:

[16.04.2014 23:49:29.525] [0x1de3a2b8] [097] json_parser - syntax error found,  forcing abort, Line 1 Column 1 
[16.04.2014 23:49:30.603] [0x1de3a2b8] [100] JSonScanner::yylex - error while reading from io device 

This for development version c6d92ba
Qt 4.8.5 mingw win7 debug
For 0.8.1 tag there is no issue.

QJson doesn't work with QNetworkReply

Hi,

when I want to parse from a QNetworkReply, I always get back an empty QVariant.
It works when I first buffer the content of the QNetworkReply object with readAll and hand over the resulting QByteArray to QJson::parse.

But as QNetworkReply also is a QIODevice, it should work for these kind of objects, too. Apart from that, in many cases, QJson will be used to parse some reply to a networkrequest.

regards,
Roman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.