0
我想解析this使用Qt5和C++使用QJsonDocument和QJsonObject的JSON Web-API如here。但是我无法访问QJsonObject的JSON值。为什么我不能用Qt5/C++解析Cryptsy JSON API?
这是我到目前为止已经试过:
// Contains the whole API as QString...
QString data = QString(reply->readAll());
// Reads the JSON as QJsonDocument...
QJsonDocument jsonResponse = QJsonDocument::fromJson(data.toUtf8());
// Reads the JSON as QJsonObject...
QJsonObject jsonObject = jsonResponse.object();
现在我有我的目标做好了准备,但在尝试访问的JSON的值以某种方式失败:
// This returns an empty string ""!?!
qDebug() << jsonObject.value("success").toString();
好,也许我得到了错误的钥匙:
// Let's check the keys...
QStringList stringList = jsonObject.keys();
for (QStringList::Iterator it = stringList.begin(); it != stringList.end(); ++it)
{
// This returns "success" and "return" - huh!?!
qDebug() << *it;
}
好吧,关键是很满意,为什么它不工作?
// Let's check the values by using the keys directly...
for (QStringList::Iterator it = stringList.begin(); it != stringList.end(); ++it)
{
// This returns empty strings "" and "" - now what?!?
qDebug() << jsonObject.value(*it).toString();
}
这又一次没有任何意义。我看不出为什么我不能通过键访问JSON对象的值。任何想法?
我试着在其他JSON API(例如this之一)上完全相同的代码,没有任何问题。我完全陷在这里。