dougou5852 2011-04-03 01:52
浏览 96
已采纳

如何使用PHP解析JSON字符串

I have a JSON string that has 1-n numbers of lat/lng records. It looks something like this:

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

What is a good way to parse this to get lat/lng values loop? And do the escaped double quotes impact the parsing?

Thanks, Alex

  • 写回答

4条回答 默认 最新

  • drny60365 2011-04-03 01:59
    关注
    $ll = '[{"lat":37.790388261934424,"lng":-122.46047996826172},{"lat":37.789608231530124,"lng":-122.46344112701416}]';
    $ll = json_decode($ll);
    print_r($ll);
    

    Prints...

    Array
    (
        [0] => stdClass Object
            (
                [lat] => 37.7903882619
                [lng] => -122.460479968
            )
    
        [1] => stdClass Object
            (
                [lat] => 37.7896082315
                [lng] => -122.463441127
            )
    
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?