[SOLVED] QJsonobject value returns NULL
-
HI
I am getting some JSON format info from web API. It is retrieving data properly.
@
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonAsItem.toUtf8());
QJsonObject jsonObject = jsonDocument.object();@jsonAsItem is
@{"Id":5,"Name":"name1"}@but jsonobject returns NULL.
Can any one help me with this?
-
Hi,
Did you check whether the parsing returns an error ?
Also, can you show the exact content of the json data you are getting ?
-
Hi,
parseerror errorstring also returns NULL.
This is what i am getting from web API :
@"{"Id":5,"Name":"name1"}"@[edit: added missing coding tags @ SGaist]
-
@
QString testData("{"Id":5,"Name":"name1"}");
QJsonParseError parserError;
QJsonDocument doc = QJsonDocument::fromJson(testData.toUtf8(), &parserError);
qDebug() << pareserError.errorString();
qDebug() << doc.object();
@parserError returns "no error occurred"
and doc.object() returns the correct value -
Yes. For me too parse error coming as no error occured and jsondocument.object returns the value. Thanks :)
-
So you have everything working now ?
-
All the reading part is success. I am able to retrieve the information from jsonobject and array. Thanks for your help.
But having one more doubt. Now i need to call the POST web API for DB insertion. How to do that? Any idea.
I have below web URL (POST method):
http://localhost:49579/api/pdtdata/
I need to pass the below object as a input param to that method:
{
"barcode":"6281002505888",
"descr":"TestPDT",
"doc_type":"GR",
} -
Using QNetworkAccessManager::post method
-
Done. Thanks.