我有一个嵌套的JSON文件显示嵌套的JSON在laravel 5.2
{
"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
在我的路线文件我已经做json_decode解码这个数据给一个变量“交易”,并通过它来查看
Route::get('/', function() {
$transaction = json_decode(file_get_contents('xapojson.txt'));
return view('transaction', compact('transaction'));
});
现在,在交易视图我不得不从这个嵌套JSON显示数据。 我已经尝试了很多变化,并搜索谷歌和stackoverflow,但没有奏效。 我发现这有点有用Check this out。但它也没有进入更多的嵌套。
在我来显示这些DATAS的观点: -
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
请大家帮我上显示上述领域。
尝试此我得到错误后良好。 'ErrorException in 64a884a3b8243906c26295b5c5674b98d081a606.php line 2: 未定义的属性:stdClass :: $ from(View:/home/yash/website/resources/views/transaction.blade.php)' –
这是因为有些资源没有“从......”开始。你可以在显示之前使用条件查询我将更新相同的代码段 –
同样适用于其他人以及json响应对每个资源都有不同的值集合希望您了解代码中的逻辑 –