print this json?

1

How can I access the elements of this json?

string(305) "{"puesto":"181","sexo":"Hombre","edad":"28","experienciaPuesto":"1","diasTrabajados":"Lunes,Martes,Miercoles,Jueves,Viernes","id":"6","idPromocion":"61,64,69,4","habilidades":"1,3,2","paquetesLenguajes":"Excel,Power point,Word","conocimientosEspecificos":"1,2","sueldo":"600.00","ultimoGradoEstudios":"6"}"

I wanted to do it this way but it does not work out

echo $solicitudEmpleo['puesto'];
    
asked by Carlos Enrique Gil Gil 23.04.2018 в 19:00
source

2 answers

2

What you have is a text string, not an object.

First you have to convert that JSON text to a JSON object.

$obj = json_decode($solicitudEmpleo,true);
echo $obj["puesto"];

The true is to be able to handle it as an "arrangement".

    
answered by 23.04.2018 / 19:03
source
0

You have to decodear the json with json_decode() are thus:

<?php
  $json = $solicitudEmpleo;

  var_dump(json_decode($json));
  var_dump(json_decode($json, true));

  $solicitudEmpleoArray = json_decode($solicitudEmpleo);
  // esto imprime "181"
  var_dump($solicitudEmpleoArray['puesto']);

?>

The first one prints it in a object and the second one in a array indexed.

    
answered by 23.04.2018 в 19:07