dsjswclzh40259075 2017-09-02 19:03
浏览 109
已采纳

尝试循环数组时非法字符串偏移量

I've JSON response body then I convert it to array use json_decode() but when I trying loop one single array I received error

Illegal String Offset

this my json response

array(5) { ["StartDate"]=> string(10) "2016-08-29" ["EndDate"]=> string(10) "2016-09-01" ["Currency"]=> string(3) "IDR" ["StartBalance"]=> string(12) "100000000.00" ["Data"]=> array(20) { [0]=> array(6) { ["TransactionDate"]=> string(5) "29/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(10) "9000000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING DB" ["Trailer"]=> string(58) "2808/ACDFT/WS950519000000.00 REK KORAN DARI GIRO KE TAPRES" } [1]=> array(6) { ["TransactionDate"]=> string(5) "29/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(8) "25000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING CR" ["Trailer"]=> string(26) "08/28 95031 FOR CORPDUMMY1" } [2]=> array(6) { ["TransactionDate"]=> string(5) "29/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(9) "200000.00" ["TransactionName"]=> string(17) "BA JASA E-BANKING" ["Trailer"]=> string(36) "2908/TRCHG/WS95051BIAYA TRANSFER SME" } [3]=> array(6) { ["TransactionDate"]=> string(5) "29/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(10) "1000000.00" ["TransactionName"]=> string(17) "BYR VIA E-BANKING" ["Trailer"]=> string(51) "29/08 WSID95051 PENERIMAAN NEGARA 115110002341111" } [4]=> array(6) { ["TransactionDate"]=> string(5) "29/08" ["BranchCode"]=> string(4) "0061" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(9) "900000.00" ["TransactionName"]=> string(13) "SETORAN TUNAI" ["Trailer"]=> string(14) "PEMBUKAAN REK." } [5]=> array(6) { ["TransactionDate"]=> string(5) "30/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(8) "10000.00" ["TransactionName"]=> string(17) "BA JASA E-BANKING" ["Trailer"]=> string(36) "3008/TRCHG/WS95051BIAYA TRANSFER SME" } [6]=> array(6) { ["TransactionDate"]=> string(5) "30/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(10) "5000000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING DB" ["Trailer"]=> string(61) "3008/FTRTG/00001000110042 other bank TRANSFER VIA RTGS Dummy4" } [7]=> array(6) { ["TransactionDate"]=> string(5) "30/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(11) "70000000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING CR" ["Trailer"]=> string(53) "3008/FTSCY/WS95051 70000000.00 Ticket Payment DUMMY13" } [8]=> array(6) { ["TransactionDate"]=> string(5) "30/08" ["BranchCode"]=> string(4) "0061" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(10) "5000000.00" ["TransactionName"]=> string(8) "NK - LLG" ["Trailer"]=> string(0) "" } [9]=> array(6) { ["TransactionDate"]=> string(5) "30/08" ["BranchCode"]=> string(4) "0998" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(9) "800000.00" ["TransactionName"]=> string(15) "SETORAN VIA CDM" ["Trailer"]=> string(25) "3008 WSID:Z9991 DUMMY16" } [10]=> array(6) { ["TransactionDate"]=> string(5) "31/08" ["BranchCode"]=> string(4) "0015" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(10) "1000000.00" ["TransactionName"]=> string(13) "NK - KU MASUK" ["Trailer"]=> string(0) "" } [11]=> array(6) { ["TransactionDate"]=> string(5) "31/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(8) "30000.00" ["TransactionName"]=> string(9) "BIAYA ADM" ["Trailer"]=> string(0) "" } [12]=> array(6) { ["TransactionDate"]=> string(5) "31/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(8) "11100.00" ["TransactionName"]=> string(5) "BUNGA" ["Trailer"]=> string(0) "" } [13]=> array(6) { ["TransactionDate"]=> string(5) "31/08" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(7) "2220.00" ["TransactionName"]=> string(11) "PAJAK BUNGA" ["Trailer"]=> string(0) "" } [14]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(9) "100000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING DB" ["Trailer"]=> string(56) "0109/FTSCY/WS95051 100000.00 Online Transfer PT DUMMY2" } [15]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0061" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(10) "3000000.00" ["TransactionName"]=> string(8) "NK - LLG" ["Trailer"]=> string(0) "" } [16]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(9) "250000.00" ["TransactionName"]=> string(17) "TRSF E-BANKING DB" ["Trailer"]=> string(44) "0109/FTSCY/WS95051 250800.00 Transfer DUMMY1" } [17]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0000" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(9) "100000.00" ["TransactionName"]=> string(17) "BA JASA E-BANKING" ["Trailer"]=> string(36) "0109/TRCHG/WS95051BIAYA TRANSFER SME" } [18]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0101" ["TransactionType"]=> string(1) "C" ["TransactionAmount"]=> string(8) "10000.00" ["TransactionName"]=> string(11) "KR OTOMATIS" ["Trailer"]=> string(20) "DUMMY7 039903811112" } [19]=> array(6) { ["TransactionDate"]=> string(4) "PEND" ["BranchCode"]=> string(4) "0038" ["TransactionType"]=> string(1) "D" ["TransactionAmount"]=> string(9) "100000.00" ["TransactionName"]=> string(13) "TARIKAN TUNAI" ["Trailer"]=> string(0) "" } } }

this JSON to array

$output = curl_exec($ch); // This is API Response
        curl_close($ch);
        $result = json_decode($output,true);

        return view("bca.cekmutasi", [
            "result" => $result
            ]);

this my view

@if (isset($result))
@foreach ($result as $key => $value)
<div class="col-xs-6">
  <ul class="list-unstyled" style="line-height: 2">
  <li><span class="fa fa-circle text-success"></span> TransactionDate : <b>{{ $value['StartDate']['EndDate']['Currency']['StartBalance']['StartBalance']['Data'][0]['TransactionDate'] }}</b></li>
  </ul>
</div>
@endforeach
@endif

and if I just put {{ $result['Data'][0]['TransactionDate'] }} without foreach its show the result

How do I fix this ?

  • 写回答

2条回答 默认 最新

  • duanjue7745 2017-09-02 19:39
    关注

    Your response is not an array, you need to do this on the foreach

    @if (isset($result))
    @foreach ($result['Data'] as $key => $value)
    <div class="col-xs-6">
      <ul class="list-unstyled" style="line-height: 2">
      <li><span class="fa fa-circle text-success"></span> TransactionDate : <b>{{ $value['TransactionDate'] }}</b></li>
      </ul>
    </div>
    @endforeach
    @endif
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目