一尘不染

如何使用PHP解析JSON字符串

json

我有一个包含1-n纬度/经度记录的JSON字符串。看起来像这样:

{\"lat\":37.790388261934424,\"lng\":-122.46047996826172},{\"lat\":37.789608231530124,\"lng\":-122.46344112701416}

什么是解析此值以获取经纬度值循环的好方法?转义的双引号是否会影响解析?

谢谢亚历克斯


阅读 258

收藏
2020-07-27

共1个答案

一尘不染

$ll = '[{"lat":37.790388261934424,"lng":-122.46047996826172},{"lat":37.789608231530124,"lng":-122.46344112701416}]';
$ll = json_decode($ll);
print_r($ll);

打印…

Array
(
    [0] => stdClass Object
        (
            [lat] => 37.7903882619
            [lng] => -122.460479968
        )

    [1] => stdClass Object
        (
            [lat] => 37.7896082315
            [lng] => -122.463441127
        )

)
2020-07-27