API와 연결을 시도하고 있습니다. 에 대한 작업을 배우고 싶습니다. 나는 문자열로 JSON 변환하려고 (나는 Laravel 작업)하지만 난 변환 된 문자열을 에코 경우는 나에게이 오류 제공 :JSON을 String으로 변환 할 수 없습니다. (PHP 및 Laravel)
public function index()
{
$url = 'https://www.quandl.com/api/v3/databases/WIKI.json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$string = json_decode($data, true);
curl_close($ch);
return view('index', compact('string'));
}
: 이것은 내 HomeController.php입니다
ErrorException in helpers.php line 531:
htmlentities() expects parameter 1 to be string, array given (View: /home/stackingcoder/development/PHP/internetstuffer/resources/views/index.blade.php)
을
나는 템플릿 엔진 블레이드를 사용하고, 그래서 내 에코는 다음과 같습니다
{{ $string }}
편집 :
를결과로 배열이 필요합니다. API 호출을 배열로 변환하는 방법은 무엇입니까? 그래서 이런 식으로 데이터를 분할 할 수 있습니다에서 :
echo $data['database']['name'];