dongwu5801 2016-01-06 20:17
浏览 41
已采纳

仅使用标记创建数组 - Json解码[重复]

This question already has an answer here:

How do I return only all the urls item "webformatURL" using json decode?

{
    "totalHits":500,
    "hits":[
        {
            "previewHeight":84,
            "likes":37,
            "favorites":42,
            "tags":"yellow, natural, flower",
            "webformatHeight":360,
            "views":11218,
            "webformatWidth":640,
            "previewWidth":150,
            "comments":8,
            "downloads":6502,
            "pageURL":"https://example.com/en/yellow-natural-flower-715540/",
            "previewURL":"https://example.com/static/uploads/photo/2015/04/10/00/41/yellow-715540_150.jpg",
            "webformatURL":"https://example.com/get/ee34b40a2cf41c2ad65a5854e4484e90e371ffd41db413419cf3c271a6_640.jpg",
            "imageWidth":3020,
            "user_id":916237,
            "user":"916237",
            "type":"photo",
            "id":715540,
            "userImageURL":"https://example.com/static/uploads/user/2015/04/07/14-10-15-590_250x250.jpg",
            "imageHeight":1703
        },

    ],
    "total":7839
}

I try:

    $test= json_decode($json);
    $result= $test->webformatURL;

Error: warning-undefined-property-stdclass::webformatURL

I've read the manual but I doubt then I would see an example in practice json_decode

Thanks for any help

</div>
  • 写回答

1条回答 默认 最新

  • dongxin5429 2016-01-06 20:20
    关注

    Did you mean?

    $result = $test->hits[0]->webformatURL;
    

    If you want to extract only this field from the object, you can do:

    $urls = [];
    foreach($test->hits as $hit) {
        $urls[] = $hit->webformatURL;
    }
    var_dupm($urls);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境