Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何显示下面给出的json中的tld值_Php_Laravel - Fatal编程技术网

Php 如何显示下面给出的json中的tld值

Php 如何显示下面给出的json中的tld值,php,laravel,Php,Laravel,在下面的json中,我需要显示tld的值,即co.uk、eu、live、org Array ( [tldlist] => Array ( [tld] => Array ( [0] => Array ( [tld] => co.uk ) [1] => Array ( [tld] => eu ) [2] => Array ( [tld] => live ) [3] => Array ( [tld] => org ) [4] => Ar

在下面的json中,我需要显示tld的值,即co.uk、eu、live、org

Array ( [tldlist] => Array ( [tld] => Array ( [0] => Array ( [tld] => co.uk ) [1] => Array ( [tld] => eu ) [2] => Array ( [tld] => live ) [3] => Array ( [tld] => org ) [4] => Array ( [tld] => Array ( ) ) ) [tldcount] => 5 ) [Command] => GETTLDLIST [APIType] => API [Language] => eng [ErrCount] => 0 [ResponseCount] => 0 [MinPeriod] => Array ( ) [MaxPeriod] => 10 [Server] => SJL1VWRESELL_T [Site] => eNom [IsLockable] => Array ( ) [IsRealTimeTLD] => Array ( ) [TimeDifference] => +0.00 [ExecTime] => 0.000 [Done] => true [TrackingKey] => 7cbc3d47-c11c-4a39-8387-448777e82af5 [RequestDateTime] => 5/14/2018 12:21:18 AM [debug] => Array ( ) ) 1
查找以下我的刀片代码:

 @foreach($final_data1['tldlist']['tld'] as $key)

    {{$key}}<br>

 @endforeach
@foreach($final_data1['tldlist']['tld']作为$key)
{{$key}}
@endforeach
请建议我在blade文件中进行更正,以显示上述json中的tld。

初步说明:您显示的“json”不是json,它是
print\r()
的输出


因为JSON只是一个字符串,所以需要首先对其进行解码。各国:

功能

json_解码(字符串$json[,bool$assoc=FALSE[,int$depth=512[,int$options=0]])

参数

$json 正在解码的json字符串

$assoc 如果为TRUE,则返回的对象将转换为关联数组

因此,解码后,关联数组将作为对象进行访问:

$data = json_decode($json);
$tld = $data->tldlist;
如果要将其解码为数组,请将
true
作为第二个参数传递:

$data = json_decode($json, true);
$tld = $data['tldlist'];
我建议在控制器中解码。这样,视图就不需要关心数据的传递方式

假设您有一个JSON字符串并希望将其作为数组访问:

return view('your_blade_view')->with('final_data1', json_decode($data, true));
如果坚持在刀片文件中执行此操作,请使用以下代码段:

@foreach($final_data1['tldlist']['tld'] as $key)

    {{$key}}<br>

@endforeach
@foreach($final_data1['tldlist']['tld']作为$key)
{{$key}}
@endforeach
尝试
{{$key['tld']}}
当我使用这个时,我得到的错误是“未定义索引:tldlist”