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...
我的问题是如何在我的Json文件中获得“nom”和“prenom”
我的JSON文件网址:http://trackanddragutils.azurewebsites.net/json/json.php
感谢您的帮助!! :ⅰ)
答案 0 :(得分:0)
试试这个:
QVariantList testList = address["test"].toList();
QVariantMap map = testList[0].toMap();
qDebug() << "Nom is " << map["nom"].toString();
qDebug() << "Prenom is " << map["prenom"].toString();