Looking for some help.. Don't know the best approach to this issue... I'm pushing a new reference onto an array but the "true" value is being inserted with quotes, which fails my json format.
while( $row = mysqli_fetch_assoc($res) ) {
if($row['id']=="2"){
$row['children']= 'true';
}
$data[] = $row;
}
echo json_encode( $data);
Outputs
[{"id":"2","name":"john","text":"john","parent_id":"0","children":"true"}]
When i need...
{"id":"2","name":"john","text":"john","parent_id":"0","children":true}]
How would i go about removing the qoutes or inserting it correctly first.??
"children":"true"is correct! It will be usable when you get to your javascript and convert it to a javascript object'true'is a string,trueis a boolean. You want a boolean.str_replace, please.str_replacebecause it is an unreliable hack. If you put a string in the array,json_encodeputs a string in the JSON, if you put a boolean in the array, it puts a boolean in the JSON. Instead of screwing around with the JSON string, just providejson_encodewith values that are the correct type to begin with.