Typically I write the following to retrieve data from a json document:
data[“query”].toObject()[“test”].toArray()1
This is great, but is quite “textful”. I believe the following will be better code:
data[“query”][“test”]1
which removes all the type conversion part.
And I believe this is possible with the current settings. Because we have methods like isArray, isObject etc, the framework actually knows the internal type of the QJsonValue, so we can return the value accordingly, like:
QJsonValue QJsonValue::operator[](int i)
{
if (this->isArray())
return this->toArray()[i];
}
QJsonValue QJsonValue::operator[](QString s)
{
if (this->isObject())
return this->toObject()[s];
}
And this will simplify the written code quite a lot!
Any suggestions?
↧