Hello!
String .json:
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "id": 1, "options": {"strokeWidth": 3}, "properties": {"balloonContent": "Π‘ΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ Π±Π°Π»ΡΠ½Π°", "hintContent": "Π’Π΅ΠΊΡΡ ΠΏΠΎΠ΄ΡΠΊΠ°Π·ΠΊΠΈ"}, "geometry": { "type": "LineString", "coordinates": [ [ 55.80899899270488, 37.77442932128906 ], [ 55.800895029938275, 37.74696350097656 ], [ 55.795877445664104, 37.709197998046875 ] ] } } ] } The user enters the coordinates in the field, for example: [[00.0000, 00.0000], [11.0000, 11.0000], [22.0000. 22,0000]]
Further php code:
<?php $json = file_get_contents('data.json'); $data = json_decode($json, true); $coordinates = $_POST['coordinates']; $arr['geometry']['coordinates'] = $coordinates; array_push($data['features'], $arr); $json = json_encode($data, JSON_UNESCAPED_UNICODE); file_put_contents('data.json', $json); ?> After this, the entry in .json looks like this:
"coordinates": "[ [ 55.80899899270488, 37.77442932128906 ], [ 55.800895029938275, 37.74696350097656 ], [ 55.795877445664104, 37.709197998046875 ] ]" And you need to be so (without quotes):
"coordinates": [ [ 55.80899899270488, 37.77442932128906 ], [ 55.800895029938275, 37.74696350097656 ], [ 55.795877445664104, 37.709197998046875 ] ] Tell me, please, what is the error? How to fix? Thank.
json_decodewhat you received from the user, i.e. .json_decode($coordinates)- teran