Cannot parse Json data
-
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();
}
@This code return me "unterminated object"... I submitted it as a bug.. But I may be wrong.. Do you know why ?
-
Hi,
Your JSON is invalid, you need to use double quotes not single
-
Ah okay ! I was confusing because this json was working on http://jsonviewer.stack.hu/ !
-
They might be a bit less picky on the format
-
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)