S
S
Saharman2018-06-03 19:23:45
Qt
Saharman, 2018-06-03 19:23:45

Why is QJsonObject always empty?

I get json using a get request and try to process it somehow. The problem is that the QJsonObject is always empty (even though the QJsonDocument contains all the data). How to fix?

QByteArray qb(reply->readAll());
        QJsonObject json = QJsonDocument::fromJson(qb).object();

Tried it like this:
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-06-03
@vt4a2h

Well, most likely there is an array, and not a single object means. Try array(). And it's even better to check what you got, there are isArray, isObject, isNull, isEmpty methods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question