QT读取JSON

void MainWindow::readJson(QString fileName)
{
    QString szContent = NMyUtils::readFile(NMyUtils::getFileFullPath(fileName));

    QJsonDocument jDoc = QJsonDocument::fromJson(szContent.toUtf8());
    QJsonObject jObj = jDoc.object();
    QJsonArray jReminderItems = jObj.value(QString("Reminder")).toArray();

    foreach (const QJsonValue & item, jReminderItems)
    {
        QJsonValue eName = (item.toObject())["EventName"];
        QJsonValue tBegin = (item.toObject())["TimeBegin"];
        QJsonValue tDue = (item.toObject())["TimeDue"];
        QJsonValue comments = (item.toObject())["Comments"];
        const NMyEvent *myevent = NMyEvent::newEvent(eName.toString(),tBegin.toString(),tDue.toString(),comments.toString());

        eventArray->append(*myevent);
    }
}

Comments are closed.