json_decode to array

前端 未结 12 1354
野的像风
野的像风 2020-11-22 01:31

I am trying to decode a JSON string into an array but i get the following error.

Fatal error: Cannot use object of type stdClass as array in C:\\w

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 02:05

    I hope this will help you

    $json_ps = '{"courseList":[  
                {"course":"1", "course_data1":"Computer Systems(Networks)"},  
                {"course":"2", "course_data2":"Audio and Music Technology"},  
                {"course":"3", "course_data3":"MBA Digital Marketing"}  
            ]}';
    

    Use Json decode function

    $json_pss = json_decode($json_ps, true);
    

    Looping over JSON array in php

    foreach($json_pss['courseList'] as $pss_json)
    {
    
        echo '
    ' .$course_data1 = $pss_json['course_data1']; exit; }

    Result: Computer Systems(Networks)

提交回复
热议问题