D
D
Denis Kiselev2016-12-06 17:01:48
PHP
Denis Kiselev, 2016-12-06 17:01:48

how to generate json in php?

Hello. Tell me how to correctly generate a json file so that it looks like this at the output:

{
    "type": "FeatureCollection",
    "features": [
        {"type": "Feature", "id": 0, "geometry": {"type": "Point", "coordinates": [55.831903, 37.411961]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
        {"type": "Feature", "id": 1, "geometry": {"type": "Point", "coordinates": [55.763338, 37.565466]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
        {"type": "Feature", "id": 2, "geometry": {"type": "Point", "coordinates": [55.763338, 37.565466]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}},
        {"type": "Feature", "id": 3, "geometry": {"type": "Point", "coordinates": [55.744522, 37.616378]}, "properties": {"balloonContent": "Содержимое балуна", "clusterCaption": "Еще одна метка", "hintContent": "Текст подсказки"}}
    ]
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Godless, 2016-12-06
@kiselev-webmaster

you create an array with pairs key - value
though in a cycle though where. If you need a subsection in json, then make a nested array.
Well, then
echo json_encode($array);

S
Snewer, 2016-12-06
@Snewer

echo json_encode([
'type' => 'FeatureCollection',
'features' => [
    ['type' => 'Feature'],
   // ...
]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question