[英]SyntaxError:missing ; before statement [PHP array to Javascript Array]
This is how I get php array from api using php file_get_contents这就是我使用 php file_get_contents 从 api 获取 php 数组的方法
<?php
$array=json_decode(file_get_contents("https://www.example.com.my/sandbox/api/mobileapp.php?token=123123&action=listing_for_map"), true);
$arr= json_encode($array['get']);
?>
Here how I put the php array to javascript array and how I get the data在这里,我如何将 php 数组放入 javascript 数组以及如何获取数据
var geoPoint = '<?php echo $arr ;?>';
for (var i = 0; i < 1000; ++i) {
var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate)
var marker = new google.maps.Marker({
position: latLng,
draggable: true,
icon: markerImage
});
markers.push(marker);
}
Each time I run the code, I got this error.每次运行代码时,都会出现此错误。 SyntaxError:missing ;语法错误:缺少; before statement声明前
Can anyone tell me where actually I did wrong?谁能告诉我我到底做错了什么? Thank in advance预先感谢
Wrapping your JSON in single quotes defines it as a string.用单引号包裹 JSON 将其定义为字符串。 You want it to be defined as an object:你希望它被定义为一个对象:
var geoPoint = <?php echo $arr ;?>;
As others' comments pointed out, you are also missing a semicolon on this line:正如其他人的评论所指出的,您还缺少这一行的分号:
var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate);
You're missing a semicolon after var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate)
.您在var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate)
之后缺少分号。 It should be var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate);
它应该是var latLng = new google.maps.LatLng(geoPoint.get[i].google_coordinate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.