Solved Reading and Writing JSON
-
this is the output of my .php link
[ { "LeaderCode": "GNL0001" }, { "LeaderCode": "GNL0002" } ]
well from this i just need to get those values "GNL0001 & GNL002" and add them to my combo box , please help me out with this.
-
-
@kshegunov thnks for your response but my question is how do I add the values to my combo box???
-
Get the strings through the
QJsonDocument
(there are examples in the docs) and then use QComboBox::addItem to add them to the actual combo box. -
@kshegunov well look at this,
void MainWindow::datainDaHouse2(QByteArray data) { //first qDebug()<< "Jason value" +data; QJsonDocument doc = QJsonDocument::fromJson(data); QJsonArray array = doc.array(); QJsonObject object = array.at(0).toObject(); QString code = object["LeaderCode"].toString(); ui->comboBox_54->insertItem(3,code); //second qDebug()<< "InsertCode" +code; }
well this is my current code and my output for qDebug is,
//first
"Jason value<pre>[\n {\n "LeaderCode": "GNL0001"\n },\n {\n "LeaderCode": "GNL0002"\n }\n]</pre>"
//second here where my output getting blank
"InsertCode"
So any suggestions ? And sorry if I'm wrong with the code ,I'm newbie . -
well these are the changes I've done now its working good
void MainWindow::datainDaHouse2(QByteArray data) { data = data.replace("<pre>", "").replace("</pre>", ""); QJsonDocument doc = QJsonDocument::fromJson(data); QJsonArray array = doc.array(); for(int i=0 ;i<array.size();i++){ QJsonObject object = array.at(i).toObject(); QString code = object["LeaderCode"].toString(); ui->comboBox_54->insertItem(1,code); qDebug()<< "InsertCode" +code; } }
thnk u for your response :)
-
please mark the topic as solved
-
@sankarapandiyan I've marked it Solved long back.