I have this problem when consulting the data of a webService
basic in Qt
.
After making a request GET
with QNetworkAccesManager
and using the method readAll()
of QNetworkReply
, I am receiving this:
array(2) {
["HOST"]=>
string(9) "localhost"
["authorization"]=>
string(32) "c07e6adab2de7403a8afb8e7c25c7e3e"
}
{
"estado": 1,
"datos": [
{
"idContacto": "1",
"primerNombre": "Pedro",
"primerApellido": "Revelo",
"telefono": "312090934",
"correo": "[email protected]",
"idUsuario": "1"
},
{
"idContacto": "2",
"primerNombre": "francisco",
"primerApellido": "franco",
"telefono": "312090934",
"correo": "[email protected]",
"idUsuario": "1"
},
{
"idContacto": "3",
"primerNombre": "gabriel",
"primerApellido": "salguedo",
"telefono": "8788459",
"correo": "gabri@correo",
"idUsuario": "1"
}
]
}
This is the method I use to receive the answer:
if (reply->error() == QNetworkReply::NoError) {
QStringList nombre;
QStringList correo;
QStringList claveApi;
QString strReply = (QString)reply->readAll();
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8()); //AQUI NO HACE NADA
QJsonObject jsonObject =jsonResponse.object();
foreach (const QJsonValue & value, jsonObject) {
QJsonObject obj = value.toObject();
nombre.append(obj["nombre"].toString());
correo.append(obj["correo"].toString());
claveApi.append(obj["claveApi"].toString());
}
for(int i=0; i < nombre.length(); i++){
ui->lineEdit_apikey->setText(claveApi[i]);
}
delete reply;
}
else {
qDebug() << "Failure" <<reply->errorString();
delete reply;
}