【问题标题】:how to display specify object value from JSON in laravel table view blade如何在 laravel 表视图刀片中显示来自 JSON 的指定对象值
【发布时间】:2020-06-01 04:04:22
【问题描述】:

我设法在刀片表中显示某个值,但没有管理另一个值...我想显示值

description

在里面

irel__com_access_level

来自我的 json 响应

....这是我的响应 json 代码

{
            "ID": "cust1",
            "PWD": "W6ph5Mm5Pz8GgiULbPgzG37mj9g=",
            "NICK_NAME": "CUST1",
            "PWD_INVALID_HIT": "0",
            "PWD_CREATE_DT": "2019/07/22 15:57:15",
            "INSTITUTION_ID": "C01",
            "ACL_ID": "L04",
            "LOGIN_DT": "2019/07/22 15:57:15",
            "LOGIN_STS_ID": "N",
            "STS_ID": "C08",
            "TYPE_ID": "U00",
            "UPD_DT": "2019/07/22 15:57:15",
            "EMAIL_ID": "cust1@gmail.com",
            "PHONE_NO_ID": "0",
            "HP_ID": "0                        ",
            "CRT_DATE_DELETED": null,
            "irel__com_access_level": {
                "ID": "L04",
                "DESCRIPTION": "CUSTOMER",   // i want to display this
                "IS_CREATE": "Y",
                "IS_READ": "Y",
                "IS_UPDATE": "Y",
                "IS_DELETE": "N",
                "STS_ID": "R01",
                "UPD_ID": "shukrimb",
                "UPD_DT": "2018/06/26 11:15:10"
            },

        },

在我的控制器中

 public function index()
    {

        $response =  $this->client->get('getUserIndex')->getBody();
        $content = json_decode($response->getContents());

        return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data]);

    }

我的刀片文件

 @foreach($content as $i=>$user)
                        @php
                            $currentRecordno = 1;
                        @endphp
                        <tr>
                            <td>{{ $currentRecordno + $i }}</td>
                            <td>{{ $user->ID }}</td>
                            <td>{{ $user->NICK_NAME }}</td>
                            <td>{{ $user->PWD_INVALID_HIT }}</td>
                            <td>{{ $user->???? }}  </td>

【问题讨论】:

  • 如果您的响应是User 的对象实例,正如我从上面看到的,您可以像这样访问irel__com_access_level 属性:$user-&gt;irel__com_access_level['DESCRIPTION']
  • 只是尝试你的代码,但出现“不能使用 stdClass 类型的对象作为数组”这样的错误

标签: javascript php json laravel guzzle


【解决方案1】:

在您的控制器中执行以下操作:

public function index()
    {

        $response =  $this->client->get('getUserIndex')->getBody();
        $content = json_decode($response->getContents(), true); //true convert your JSON to array

        return view('configuration.comuserprofiles.ComUserProfilesList', ['content' => $content->data]);

    }

然后在您的 Blade 中,您可以通过以下方式达到此目的:

$user['irel__com_access_level']['DESCRIPTION']

【讨论】:

  • 嗨先生...错误返回“试图获取非对象的属性”
  • 尝试dd() 每一关,例如在你的刀片中的foreach 循环中写这个:@php dd($user); @endphp,然后如果它是你的成功返回然后dd($user['irel__com_access_level']),然后如果它是你的成功回报这样做dd($user['irel__com_access_level']['DESCRIPTION'])----通过这种方式你可以找出你的问题在哪里
猜你喜欢
  • 2020-10-10
  • 2019-08-31
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
  • 2020-02-03
  • 2020-09-13
相关资源
最近更新 更多