从JSON文件中读取数据?

时间:2013-12-04 02:52:28

标签: c++ json blackberry blackberry-10 blackberry-cascades

QVariant list = ja.loadFromBuffer(buffer);
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);                      
AbstractPane *root = qml->createRootObject<AbstractPane>();
ListView *listView = root->findChild<ListView*>("liste");
GroupDataModel *model = new GroupDataModel(QStringList() << "nom" );
QVariantMap addresses = list.toMap();

foreach(QVariant var, addresses) {
    QVariantMap addressMap = var.toMap();
    qDebug() << "CategoryName is " <<addresses;
    model->insert(addressMap);
}

listView->setDataModel(model);

当我运行此结果时出现:

 QMap(("test", QVariant(QVariantList, (QVariant(QVariantMap, QMap(("id", QVariant(QString, "1") ) ( "nom" ,  QVariant(QString, "samar") ) ( "prenom" ,  QVariant(QString, "20") ) )  ) ,  QVariant(QVariantMap, QMap(("id", QVariant(QString, "11") ) ( "nom" ,  QVariant(QString, "sarra") ) ( "prenom" ,  QVariant(QString, "1") ) )  ) ,  QVariant(QVariantMap, QMap(("id", QVariant(QString, "21") ) ( "nom" ,  QVariant(QString, "akgc") ) ( "prenom" ,  QVariant(QString, "3") ) )  ) ,  QVariant(QVar...
  1. 我的问题是如何在我的Json文件中获得“nom”和“prenom”

  2. 我的JSON文件网址:http://trackanddragutils.azurewebsites.net/json/json.php

  3. 感谢您的帮助!! :ⅰ)

1 个答案:

答案 0 :(得分:0)

试试这个:

QVariantList testList = address["test"].toList();
QVariantMap map = testList[0].toMap();

qDebug() << "Nom is " << map["nom"].toString();
qDebug() << "Prenom is " << map["prenom"].toString();