Answer the question
In order to leave comments, you need to log in
How to represent string from mysql to json without quotes?
Help the teapot please. I can't think of anything at all.
I add markers to Yandex map using objectManager (using json)
The coordinates of objects in the database are a string (for example: 55.722012, 37.183899)
I collect JSON using json_encode Naturally,
Yandex API does not want to understand the "geometry":{"type":"Point", "coordinates":"[55.722012, 37.183899]"}
since the coordinates must be an array "geometry":{"type":"Point","coordinates":[
55.722012 , 37.183899]}
I really don't want to make changes in mysql. Is it possible to come up with a crutch when assembling json?
Short code:
while ($row = mysqli_fetch_array($result))
{
$geometry[] = array(
'type' => 'Point',
'coordinates' => '['.$row['y_coordinates'].']'
);
$employee_data[] = array (
'geometry' => $geometry
);
}
json_encode($employee_data, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK);
Answer the question
In order to leave comments, you need to log in
Probably, it is necessary not to put a string, but to put an array in coordinates. Try replacing
it with something like
A if you want the array elements to be numbers:
array_map('floatval', explode(', ', $row['y_coordinates']))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question