How to get elements from json array
-
I have the next JSON:
{"Number of people":3,"person":["Marian Marian","Badea Valentin","Ion Andrei"]}
response1 is my string with json format, and i want to print every person name. i tried jsonObject["person"][i] but it doesn't work. any help?
QString qstr = QString::fromStdString(response1); QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8()); QJsonObject jsonObject = jsonResponse.object(); int nr_rows=jsonObject["Number of people"].toInt(); for(int i=0;i<nr_rows;i++){ cout<<jsonObject["person"][i]; // how to print every element? }
-
I have the next JSON:
{"Number of people":3,"person":["Marian Marian","Badea Valentin","Ion Andrei"]}
response1 is my string with json format, and i want to print every person name. i tried jsonObject["person"][i] but it doesn't work. any help?
QString qstr = QString::fromStdString(response1); QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8()); QJsonObject jsonObject = jsonResponse.object(); int nr_rows=jsonObject["Number of people"].toInt(); for(int i=0;i<nr_rows;i++){ cout<<jsonObject["person"][i]; // how to print every element? }
-
I have the next JSON:
{"Number of people":3,"person":["Marian Marian","Badea Valentin","Ion Andrei"]}
response1 is my string with json format, and i want to print every person name. i tried jsonObject["person"][i] but it doesn't work. any help?
QString qstr = QString::fromStdString(response1); QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8()); QJsonObject jsonObject = jsonResponse.object(); int nr_rows=jsonObject["Number of people"].toInt(); for(int i=0;i<nr_rows;i++){ cout<<jsonObject["person"][i]; // how to print every element? }
-
I have the next JSON:
{"Number of people":3,"person":["Marian Marian","Badea Valentin","Ion Andrei"]}
response1 is my string with json format, and i want to print every person name. i tried jsonObject["person"][i] but it doesn't work. any help?
QString qstr = QString::fromStdString(response1); QJsonDocument jsonResponse = QJsonDocument::fromJson(qstr.toUtf8()); QJsonObject jsonObject = jsonResponse.object(); int nr_rows=jsonObject["Number of people"].toInt(); for(int i=0;i<nr_rows;i++){ cout<<jsonObject["person"][i]; // how to print every element? }
-
-
@Gojir4 said in How to get elements from json array:
QJsonArray a = jsonObject["person"].toArray();
I tried it but i have an error: calling toArray with incomplete return type