【问题标题】:how to display json data into laravel blade?如何将 json 数据显示到 laravel 刀片中?
【发布时间】:2019-02-22 06:47:50
【问题描述】:
public function bar()
{

    $lowm = new LaravelOWM();
    $for = $lowm->getWeatherForecast('lahore');
     $ff= json_decode(json_encode($for),true);
    dd($for);
}

这是我认为是多维数组的输出,我只想打印一些东西。告诉我每个循环的答案。

array:3 [▼
  "city" => array:6 [▼
    "id" => 1172451
    "name" => "Lahore"
    "country" => "PK"
    "population" => null
    "lat" => 31.5196
    "lon" => 74.3263
  ]
  "sun" => array:2 [▼
    "rise" => array:3 [▼
      "date" => "2018-09-17 00:48:17.000000"
      "timezone_type" => 3
      "timezone" => "UTC"
    ]
    "set" => array:3 [▼
      "date" => "2018-09-17 13:05:08.000000"
      "timezone_type" => 3
      "timezone" => "UTC"
    ]
  ]
  "lastUpdate" => array:3 [▼
    "date" => "2018-09-17 23:00:29.303267"
    "timezone_type" => 3
    "timezone" => "UTC"
  ]
]

我只想显示城市名称,经纬度。

【问题讨论】:

标签: arrays json laravel multidimensional-array laravel-blade


【解决方案1】:

为什么不这样?

public function bar() {
    $lowm = new LaravelOWM();
    $for = $lowm->getWeatherForecast('lahore');
    dump('City: '. $for->city->name);
    dump('Latitude: '. $for->city->lat);
    dump('Longitude: '. $for->city->lon);
}

More Here

【讨论】:

    猜你喜欢
    • 2020-01-27
    • 2020-10-10
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    相关资源
    最近更新 更多