Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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 在laravel 5.2中显示嵌套json_Php_Json_Laravel_Laravel 5 - Fatal编程技术网

Php 在laravel 5.2中显示嵌套json

Php 在laravel 5.2中显示嵌套json,php,json,laravel,laravel-5,Php,Json,Laravel,Laravel 5,我有一个嵌套的json文件 { "event_type": "INCOMING_BTC", "event_uid": "5515c5601f7b3", "datetime": "2015-03-27 21:02:37", "resources": [ { "resource_type": "transaction", "resource": {

我有一个嵌套的json文件

{
        "event_type": "INCOMING_BTC",
        "event_uid": "5515c5601f7b3",
        "datetime": "2015-03-27 21:02:37",
        "resources": [
            {
                "resource_type": "transaction",
                "resource": {
                    "id": 105062,
                    "datetime": "2015-03-27 21:02:23",
                    "description": "Money from Xapo Tip",
                    "order_type": "payment_received",
                    "from": {
                        "type": "btc_address",
                        "id": "1AqF787aPHgPRZ81kdQSeEwW46yjyrAaxR"
                    },
                    "to": {
                        "destination_type": "btc_address",
                        "destination_id": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                        "to_account": 1276
                    },
                    "generic_type": "credit",
                    "amount": "0.0000001",
                    "currency": "BTC",
                    "status": "completed",
                    "txConfidence": 1,
                    "rejection_reason": null,
                    "notes": null,
                    "base_currency": "USD",
                    "exchange_rate": null,
                    "exchange_amount": null
                }
            },
            {
                "resource_type": "address",
                "resource": {
                    "id": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                    "address": "1N65Bz88zKUDPKhUUsx8f9Qwsuo96Hqz7S",
                    "meta_data": null,
                    "label": null,
                    "total_received": "0.00000350",
                    "created_at": "2015-03-08 14:50:59",
                    "address_type": "multisig",
                    "id_account": "1276"
                }
            }
        ]
    }
我已将此文件保存在名为xapojson.txt的公用文件夹中

在我的routes文件中,我使用json_decode将该数据解码为变量“transaction”,并将其传递给view

 Route::get('/', function () {
    $transaction = json_decode(file_get_contents('xapojson.txt'));
    return view('transaction', compact('transaction'));
});
现在在事务视图中,我必须显示来自这个嵌套json的数据。 我尝试过很多变化,在谷歌和stackoverflow上搜索过,但没有任何效果。 我觉得这有点帮助。但它也没有进入更多的筑巢

在视图中,我必须显示以下数据:-

resources[0]->resource->from->type

resources[0]->resource->id

resources[0]->resource->from->id

resources[0]->resource->status

resources[0]->resource->amount

resources[0]->resource->currency

resources[0]->resource->to->destination_id

datetime

请帮助我显示上面的字段。

您可以使用下面的代码(我以div为例),您可以将其更改为table或其他任何形式

@foreach($transaction->resources as $resource)
@if(is_set($resource->from))
<div>{{$resource->from->type}}</div>
@endif
<div>{{$resource->id}}</div>
@if(is_set($resource->from))
<div>{{$resource->from->id}}</div>
@endif
<div>{{$resource->status}}</div>

<div>{{$resource->amount}}</div>

<div>{{$resource->currency}}</div>

<div>{{$resource->to->destination_id}}</div>
@endforeach
@foreach($transaction->resources as$resource)
@如果(已设置($resource->from))
{{$resource->from->type}
@恩迪夫
{{$resource->id}
@如果(已设置($resource->from))
{{$resource->from->id}
@恩迪夫
{{$resource->status}
{{$resource->amount}
{{$resource->currency}
{{$resource->to->destination_id}
@endforeach
尝试使用

 $transaction = json_decode(file_get_contents('xapojson.txt'), true);

当我用简单的php编写这段代码时,我通过

$xapo_json = file_get_contents('xapojson.txt');
$xapo_json_decoded = json_decode($xapo_json);
$from_type = $xapo_json_decoded->resources[0]->resource->from->type;
$transacid = $xapo_json_decoded->resources[0]->resource->id;
$from = $xapo_json_decoded->resources[0]->resource->from->id;
$status = $xapo_json_decoded->resources[0]->resource->status;
$amount = $xapo_json_decoded->resources[0]->resource->amount;
$currency = $xapo_json_decoded->resources[0]->resource->currency;
$to = $xapo_json_decoded->resources[0]->resource->to->destination_id;
$datetime = $xapo_json_decoded->datetime;
然后在路由文件中,我更改了

return view('transaction', compact('transaction'));

鉴于此,我使用了这个

{{ $transaction->resources[0]->resource->from->id }}

瞧,它运行得很好。
64a884a3b8243906c26295b5c5674b98d081a606.php行2:未定义属性:stdClass::$from(View:/home/yash/website/resources/views/transaction.blade.php)
这是因为一些资源并没有“from”在显示之前,您可以使用条件查询。我将更新sameSame的代码段适用于其他资源以及json响应,每个资源都有一组不同的值。希望您理解代码中的逻辑
{{ $transaction->resources[0]->resource->from->id }}