Json Parsing and comparing the values
-
Hi all,
I have json format like this->
{
"id": 7,
"sort_decs": "Identity",
"last_name": "Lawson",
},
{
"id": 8,
"sort_decs": "Identity",
"last_name": "Ferguson",
},
{
"id": 9,
"sort_decs": "Identity",
"last_name": "Funke",
},
{
"id": 10,
"sort_decs": "Identity",
"last_name": "Fields",
},
{
"id": 11,
"sort_decs": "Identity",
"last_name": "Edwards",
}In qtreewidget how can I get sort_desc value for parent1 and last_name in its childs. if the sort_decs value is repeated how can get it only once in parent1 and last_name 's in childs .
-
Hi all,
I have json format like this->
{
"id": 7,
"sort_decs": "Identity",
"last_name": "Lawson",
},
{
"id": 8,
"sort_decs": "Identity",
"last_name": "Ferguson",
},
{
"id": 9,
"sort_decs": "Identity",
"last_name": "Funke",
},
{
"id": 10,
"sort_decs": "Identity",
"last_name": "Fields",
},
{
"id": 11,
"sort_decs": "Identity",
"last_name": "Edwards",
}In qtreewidget how can I get sort_desc value for parent1 and last_name in its childs. if the sort_decs value is repeated how can get it only once in parent1 and last_name 's in childs .
@Stephen28
Before I try to answer: you sayqtreewidgetbut you have posted this in QML and Qt Quick. Are you indeed asking aboutQTreeWidgetwhich is a Qt widget, not QML? -
@Stephen28
Before I try to answer: you sayqtreewidgetbut you have posted this in QML and Qt Quick. Are you indeed asking aboutQTreeWidgetwhich is a Qt widget, not QML? -
@JonB I not understanding terms clearly bro, since I was new to qt not only qt but for It field.
@Stephen28 The point is: you posted in "QML and Qt Quick" forum but you're talking about QTreeWidget which is QtWidgets not QML/QtQuick. You should post in correct forum.
-
@Stephen28 said in Json Parsing and comparing the values:
you should also look up json itself, this is far from a valid json. file
-
@Stephen28 you have to help us first, before we can help you.
You haven't even bothered to answer the QWidget VS QML question yet.I can give you this link, so you can start fixing your json string at least
-
@Stephen28 said in Json Parsing and comparing the values:
Any one help me to resolve this one
@JonB said in Json Parsing and comparing the values:
@Stephen28
Before I try to answer: you sayqtreewidgetbut you have posted this in QML and Qt Quick. Are you indeed asking aboutQTreeWidgetwhich is a Qt widget, not QML?Nobody can answer till we know which you are targeting. If using Qt you have to know whether you chose to use widgets vs QML. Look it up/Google it is you don't know what this is about.
As an outline approach: having read in your JSON (Qt
QJson...classes, Pythonjsonmodule, whichever) you will want to transform your data from how it is now --- "flat" records/objects --- into a tree hierarchy, where items are parents and children. You need a single parent for"sort_decs": "Identity"and that have multiple children for items ("id": 7, "last_name": "Lawson"), ("id": 8, "last_name": "Ferguson"), etc. That gives you your tree structure.You will need to recognise that
"sort_decs": "Identity"occurs multiple times and create just one parent node for all of those. You will probably want a QtQMapor C++std::mapfor this, so that you can easily spot the same value for the various objects and re-use the single parent node for them. Depending, you might do this directly into theQTreeWidgetif you don't want to re-map the input objects, or you might populate theQTreeWidgetfrom your separately-built tree map hierarchy.