I have this output of json
what I want to know is how to separate each object - ie: (3,2,5 etc.) in variables to use those variables in a javascript
.
Example:
{
"procede": "1",
"status": "1",
"statusText": "Correct",
"Lugares": [{
"México": "3",
"Ecuador": "2",
"Tijuana": "5"
}]
}
this is my ws the include is for a class which has a function get_places and it works since this web service has tested it and if it throws the data
include('lugares_m.php');
$lugares_m = new lugares_m();
$lista = $lugares_m->get_lugares();
$i=0;
foreach($lista as $key => $renglon){
$arr2["$i"]=array("Mexico"=>$renglon->getMexico(),
"Ecuador"=>$renglon->getEcuador(),
"Tijuana"=>$renglon->getTijuana());
$i++;
}
$salida["procede"]="1";
$salida["status"]="1";
$salida["statusText"]="Correct";
$salida["Lugares"]=$arr2;
echo json_encode($salida,JSON_UNESCAPED_UNICODE);
return;
and this is the javascript I use
<script>
$.ajax({
url: 'ws_lugares.php',
type: 'POST',
dataType: 'json',
data: $(this).serialize(),
})
.done(function (lugares) {
console.log(lugares);
if (!lugares.error) {
let m = lugares["Mexico"];
let e = lugares["Ecuador"];
let t = lugares["Tijuana"];
console.log(m+""+e+""+t)
} else {
$('.error').slideDown('slow');
setTimeout(function () {
$('.error').slideUp('slow');
}, 3500);
}
})
.fail(function (resp) {
console.log(resp.responseText);
})
.always(function () {
console.log("complete");
});
</script>