jiveaxe
20th January 2011, 18:11
Hi, I'm trying to retrieve bookmarks from chrome/chromium; these are stored in a plain text file using json format. Have made some experiments with qjson but the best I got is the first level bookmarks.
Here a sample file: http://paste.kde.org/2933/
This is my (very ugly) code:
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(&file, &ok).toMap();
if (!ok) {
ui->plainTextEdit->appendPlainText("An error occurred during parsing");
return;
}
QVariantMap rootsMap = result["roots"].toMap();
QMapIterator<QString, QVariant> i(rootsMap);
while (i.hasNext()) {
i.next();
QVariantMap bookmarkbarMap = rootsMap[i.key()].toMap();
QVariantList childrenMap = bookmarkbarMap["children"].toList();
for(int i = 0; i < childrenMap.size(); i++) {
QVariantMap nestedMap = childrenMap.at(i).toMap();
if(nestedMap["type"].toString()=="url") {
qDebug() << nestedMap["name"].toString();
qDebug() << nestedMap["url"].toString();
qDebug() << "\n";
}
}
}
Have tryed to use only QT as explained here (http://qtwiki.org/Parsing_JSON_with_QT_using_standard_QT_library) (QScriptEngine/QScriptValue) but the examples there are too simple.
Thanks
Here a sample file: http://paste.kde.org/2933/
This is my (very ugly) code:
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(&file, &ok).toMap();
if (!ok) {
ui->plainTextEdit->appendPlainText("An error occurred during parsing");
return;
}
QVariantMap rootsMap = result["roots"].toMap();
QMapIterator<QString, QVariant> i(rootsMap);
while (i.hasNext()) {
i.next();
QVariantMap bookmarkbarMap = rootsMap[i.key()].toMap();
QVariantList childrenMap = bookmarkbarMap["children"].toList();
for(int i = 0; i < childrenMap.size(); i++) {
QVariantMap nestedMap = childrenMap.at(i).toMap();
if(nestedMap["type"].toString()=="url") {
qDebug() << nestedMap["name"].toString();
qDebug() << nestedMap["url"].toString();
qDebug() << "\n";
}
}
}
Have tryed to use only QT as explained here (http://qtwiki.org/Parsing_JSON_with_QT_using_standard_QT_library) (QScriptEngine/QScriptValue) but the examples there are too simple.
Thanks