dqk94069 2014-03-06 11:27
浏览 40
已采纳

使用PHP PDO进行JSON解码

I have a JSON string, and I want to decode this string to get php array and to add it to database, but when I try to call some part of array I dont get anything:

<?php
$json = '{"zoom":13,"tilt":0,"mapTypeId":"hybrid","center":{"lat":45.38591280296377,"lng":19.936323169799834},"overlays":[{"type":"polygon","title":"Polje 1","content":"Vojvodina","fillColor":"#ffbf1a","fillOpacity":0.3,"strokeColor":"#000","strokeOpacity":0.8,"strokeWeight":3,"paths":[[{"lat":"45.37867863632308","lng":"19.948768615722656"},{"lat":"45.370719925928746","lng":"19.941558837890625"},{"lat":"45.36227764550136","lng":"19.92816925048828"},{"lat":"45.359262240003495","lng":"19.942245483398438"},{"lat":"45.35588479505299","lng":"19.955806732177734"},{"lat":"45.35974471568275","lng":"19.958553314208984"},{"lat":"45.36312193024184","lng":"19.959583282470703"},{"lat":"45.365534102931655","lng":"19.960613250732422"},{"lat":"45.36529289029106","lng":"19.96490478515625"},{"lat":"45.37084052080666","lng":"19.970226287841797"}]]}]}';
$arr = (json_decode($json, true));
echo $arr['paths'];
?>

So why I cant print $arr['paths'] ???

  • 写回答

3条回答 默认 最新

  • dongsimu4422 2014-03-06 11:30
    关注

    Because that is an array and you can't echo it right way.. You should make use of print_r

    print_r($arr['overlays'][0]['paths']);
    

    OUTPUT :

    Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [lat] => 45.37867863632308
                        [lng] => 19.948768615722656
                    )
    
                [1] => Array
                    (
                        [lat] => 45.370719925928746
                        [lng] => 19.941558837890625
                    )
    
                [2] => Array
                    (
                        [lat] => 45.36227764550136
                        [lng] => 19.92816925048828
                    )
    
                [3] => Array
                    (
                        [lat] => 45.359262240003495
                        [lng] => 19.942245483398438
                    )
    
                [4] => Array
                    (
                        [lat] => 45.35588479505299
                        [lng] => 19.955806732177734
                    )
    
                [5] => Array
                    (
                        [lat] => 45.35974471568275
                        [lng] => 19.958553314208984
                    )
    
                [6] => Array
                    (
                        [lat] => 45.36312193024184
                        [lng] => 19.959583282470703
                    )
    
                [7] => Array
                    (
                        [lat] => 45.365534102931655
                        [lng] => 19.960613250732422
                    )
    
                [8] => Array
                    (
                        [lat] => 45.36529289029106
                        [lng] => 19.96490478515625
                    )
    
                [9] => Array
                    (
                        [lat] => 45.37084052080666
                        [lng] => 19.970226287841797
                    )
    
            )
    
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化