How to get data from URL/.php file and display in my fields
-
@jsulm well yes i've done and read the documentation but small thing is item which i added is blank.
@Vineela First, you need to make sure you parsed Json correctly. The code I posted does not do that!
Then please show your current code (reading Json and putting entries into combo box).
One more question: are you sure you actually got the reply from server with Json? -
@Vineela First, you need to make sure you parsed Json correctly. The code I posted does not do that!
Then please show your current code (reading Json and putting entries into combo box).
One more question: are you sure you actually got the reply from server with Json?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" -
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"@Vineela Your Json string is invalid as it contains <pre></pre>. You need to remove these HTML tags first.
data = data.replace("<pre>", "").replace("</pre>", ""); 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;
-
@Vineela Your Json string is invalid as it contains <pre></pre>. You need to remove these HTML tags first.
data = data.replace("<pre>", "").replace("</pre>", ""); 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;
-
-
-
object = array.at(1).toObject(); QString code = object["LeaderCode"].toString(); ui->comboBox_54->insertItem(3,code); //second qDebug()<< "InsertCode" +code;
-
object = array.at(1).toObject(); QString code = object["LeaderCode"].toString(); ui->comboBox_54->insertItem(3,code); //second qDebug()<< "InsertCode" +code;
-
@Vineela said in How to get data from URL/.php file and display in my fields:
I've done this too but got only second one so
Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.
-
@Vineela said in How to get data from URL/.php file and display in my fields:
I've done this too but got only second one so
Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.
-
@Vineela said in How to get data from URL/.php file and display in my fields:
I've done this too but got only second one so
Yes, if you do this in a loop then you need to use index (i in your case) instead of fix numbers.
-
for(int i = array.size() - 1 ; i >= 0; --i) { QJsonObject object = array.at(i).toObject(); }
-
for(int i = array.size() - 1 ; i >= 0; --i) { QJsonObject object = array.at(i).toObject(); }
-
@Vineela Not sure what you mean?
You mean if you get new data and add new entries to your combo box you then have same values several times?
In this case you need to filter new values and only add values which are not yet in the box. -
@Vineela Not sure what you mean?
You mean if you get new data and add new entries to your combo box you then have same values several times?
In this case you need to filter new values and only add values which are not yet in the box.