【问题标题】:How to access a json file via PHP [duplicate]如何通过 PHP 访问 json 文件 [重复]
【发布时间】:2018-10-16 11:06:28
【问题描述】:

我有这个 Json 文件,我想做的是访问所有“名称”属性。有没有办法访问该属性。我想用 PHP (laravel) 来做到这一点。因为这个 json 有动态名称,所以我无法找到访问它的方法。

[
[
    {
        "2": {
            "id": 2,
            "name": "Asiri Medical Hospital - Kirula Road - Colombo 05",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                },
                {
                    "id": 122,
                    "name": "Diabetologist"
                }
            ]
        },
        "3": {
            "id": 3,
            "name": "Asiri Central Hospital - Norris Canal Road-Colombo 10",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                },
                {
                    "id": 122,
                    "name": "Diabetologist"
                }
            ]
        },
        "11": {
            "id": 11,
            "name": "Ninewells Care Mother and Baby Hospital (Pvt) Ltd",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                }
            ]
  }
]

]

【问题讨论】:

标签: php json laravel web


【解决方案1】:

简单的方法是使用file_get_contents。然后json_decodefile_get_contents 的结果。

$json = json_decode(file_get_contents($path_to_file))

然后你可以使用所有不同的数组函数来获得你想要的。

【讨论】:

  • 这不是 OP 所问问题的答案。
猜你喜欢
  • 2019-10-24
  • 2013-03-01
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
  • 2015-02-23
  • 2021-06-25
  • 1970-01-01
  • 2017-02-15
相关资源
最近更新 更多