i have a json file that looks like this
{
"userList": [
{
"id": "1",
"Name": "Tom",
"lastName": "Cruise",
"email": "tom@gmail.com",
"gender": "male",
"dateOfBirth": "9.9.1990",
"street": "tom Cruse street",
"city": "New york",
"postalCode": "11445",
"phone": "123123123",
"imagePath": "0"
},
]
}
now, i need on pushButton_clicked to read all data and write it in labels. I just started Qt, and its my first time using it, and Internet is not full of information. Can you help me?
QFile file("C:/Users/CZV/Documents/userList.json");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Failed to open file";
}
QJsonDocument doc=QJsonDocument::fromJson(file.readAll());
QJsonObject obj = doc.object(); // get root
QJsonValue idVal =obj.value("id"); // get value for key "name"
QJsonValue nameVal =obj.value("Name");
QJsonValue lastNameVal =obj.value("lastName");
QJsonValue emailVal =obj.value("email");
QJsonValue genderVal =obj.value("gender");
QJsonValue dobVal =obj.value("dateOfBirth");
QJsonValue streetVal =obj.value("street");
QJsonValue cityVal =obj.value("city");
QJsonValue postVal =obj.value("postalCode");
QJsonValue phoneVal =obj.value("phone");
QJsonValue imgVal =obj.value("imagePath");
ui->clabelName->setText(nameVal.toString());
ui->clabelLastName->setText(nameVal.toString());
ui->clabelEmail->setText(emailVal.toString());
ui->clabelGender->setText(genderVal.toString());
ui->clabelDoB->setText(dobVal.toString());
ui->clabelStreet->setText(streetVal.toString());
ui->clabelCity->setText(cityVal.toString());
ui->clabelPost->setText(postVal.toString());
ui->clabelPhone->setText(phoneVal.toString());`
this is a code i try to use, but it doesnt work