douyan8961 2013-07-17 13:00
浏览 523
已采纳

使用PHP解析嵌套的JSON

{
    "listing": {
        "@attributes": {
            "domain": "example.com"
        },
        "tld": "com",
        "sld": "example",
        "owner": "John Smith"
    }
}

I am needing to iterate through this JSON array and put the values into PHP variables so that I can return the values.

Example:

echo $sld;

would print:

example

Would I need to do this with a foreach loop (and if so how would I format this) or is there a easy built in function such as extract() that will do this?

  • 写回答

2条回答 默认 最新

  • dongsha1544 2013-07-17 13:06
    关注
    <?php 
    $json = '{
        "listing": {
            "@attributes": {
                "domain": "example.com"
            },
            "tld": "com",
            "sld": "example",
            "owner": "John Smith"
        }
    }';
    
    $decoded_array = json_decode($json, true);
    echo $decoded_array['listing']['sld'];//example
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部