[Qjson-devel] Problems parsing integers
Brought to you by:
flavio_castelli
From: <luk...@em...> - 2013-03-15 12:44:10
|
Hey there, I really like this library and it's really easy to use. Sadly somehow something doesn't want to work and I don't understand why. I have a class called 'Message', Message contains two private QVariantMaps, one called Header, the other Data. I exported both QVariantMaps as a Q_PROPERTY. If I serialize the class, I get a valid JSon string: { "Data" : { "Code" : 0, "Message" : "Hello, OK" }, "Header" : { "SubType" : "Error", "Type" : "Message" }, "ID" : "" } When I try to parse it back I get the following error: Number is out of range: 0 json_parser - syntax error found, forcing abort, Line 1 Column 1 I don't understand what's wrong here. Code itself is typed as int. But when I type it as an enum I get the same error. So I guess the Json parser has problems with integers itself, because enums get serialized as integers too. I serialize/parse the class like so: inline static Message * ConvertFromString(QString JSon, bool * parsed = 0) { QJson::Parser parser; QVariant Data = parser.parse(JSon.toUtf8(), parsed); if(*parsed) // I know this can lead to an error { Message * pRequest = new Message(); QJson::QObjectHelper::qvariant2qobject( Data.toMap(), pRequest ); return pRequest; } return new pimote::Message::Message(); } QString ConvertToString() { QJson::Serializer serializer; serializer.setDoublePrecision(2); serializer.setIndentMode( QJson::IndentFull ); QVariantMap Data = QJson::QObjectHelper::qobject2qvariant(this); QString Converted = serializer.serialize(Data); qDebug() << serializer.errorMessage(); return Converted; } I see no mistake here. If I replace the int with a QString it works. But well .. I want it typed correctly. Thanks in advance, have a great weekend! Greetings from Germany Lukas Möller |