[SOLVED]QJsonDocument, QJsonObject, are showing NULL and are not loading data correctly
-
wrote on 11 Mar 2014, 18:02 last edited by
And the abve is the ONLY decent example Ive been able to find as I scour Google and other searches... Is there any way for the QT Team to create some examples? Examples for other basics would be great too for those of us who are completely new to QT.
-
You can ask for a documentation update on "the bug report system":http://bugreports.qt-project.org using a feature request.
Just to be sure, did you got that example working properly ?
-
wrote on 12 Mar 2014, 03:07 last edited by
no still not working... unable to find a working example and so far no clue as to what I'm doing wrong. Thanks for the heads up on the bug system. Any chance you can tell em whats wrong with the code example? Or provide an example that works? Ste-by-step would be nice. Thanks
-
wrote on 12 Mar 2014, 05:07 last edited by
I ran just this part:
@ file.setFileName("test.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
val = file.readAll();
file.close();
qWarning() << val;
QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
qWarning << d.isEmpty();
@
and received true.. in other words the document is not getting populated from the json. Is this a known issue? -
wrote on 12 Mar 2014, 05:12 last edited by
Ok, I figured it out. Apparently, indenting your JSON file causes problems and the QJsonDocument can not populate. I removed all the spaces and test.json formatting for readability and its now populating. Thanks all
-
AFAIK, it should not be a problem. I've run the example and it's working fine. However what may happen is that your application can't find the file. You don't check that it's been opened successfully. Using a relative path, you must ensure that the file is besides your application or just give the absolute path to your json file
-
wrote on 12 Mar 2014, 11:43 last edited by
Nah, it was finding the file just fine and was reading into my QString just fine, but apparently it wasnt liking spaces or newlines or something cause it sure enough wasnt populating. But its great now. Doing exactly what I want. Thanks again
-
You might have had some stray non printable character in the JSON.
Anyway, glad it's working now.
Can you please update the thread title prepending [solved] ? So other forum users may know a solution has been found :)
-
wrote on 12 Mar 2014, 20:37 last edited by
I dont see a way to resolve this as solved
-
Just edit your first post and modify the title
15/15