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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路