R
R
RomyGalaxy2021-11-25 11:35:02
PHP
RomyGalaxy, 2021-11-25 11:35:02

How to remove quotes of map coordinates in json_encode?

Hello, there is a code:

$json_data = array("type"=>"Feature", 
        "id"=>$arItem['ID'], 
        "geometry"=>array(
        "type"=>"Polygon", 
        "coordinates"=>[$coords]),
        "properties"=>array(
            "balloonContentHeader"=>"".$arItem['NAME']."",
            "balloonContentBody"=>"",
            "balloonContentFooter"=>"",
            "hintContent"=>"".$arItem['NAME']."",
            "type"=>"".$arItem['PROPERTY_TYPE_POINT_ENUM_ID']."")
        );
        $encode_data = json_encode($json_data);

Generates json under objectmanager yandex maps to display polygons from the database. At the output we get:
{"type": "FeatureCollection","features": [{"type":"Feature","id":"279","geometry":{"type":"Polygon","coordinates":[""]},"properties":{"balloonContentHeader":"\u041f\u043b\u043e\u0449\u0430\u0434\u043a\u0430 \u0432 \u0446\u0435\u043d\u0442\u0440\u0435","balloonContentBody":"","balloonContentFooter":"","hintContent":"\u041f\u043b\u043e\u0449\u0430\u0434\u043a\u0430 \u0432 \u0446\u0435\u043d\u0442\u0440\u0435","type":"1"}}]}


But the polygons are not displayed because the coordinates":[" are quoted, and according to the rules of the objectmanager, the coordinates of the polygons must be an unquoted value in json. And it should look like this:
"coordinates":[]

How to make json_encode not add quotes to coordinates value? I have tried many options, but none of them gives the desired result.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toxa82, 2021-11-25
@toxa82

Form the $coords variable as an array of coordinates, not a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question