How can I decode json in PHP 5.1?

前端 未结 8 954
孤街浪徒
孤街浪徒 2020-12-16 20:10

json_decode function is not part of PHP 5.1, so I cannot use it. Is there any other function for this version?

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 20:44

    You can use jsonwrapper library...

    jsonwrapper implements the json_encode function if it is missing, and leaves it alone if it is already present. So it is nicely future-compatible.

    Download here: jsonwrapper

    To use just do:

    require ("jsonwrapper.php");
    
    
    $data = array('idx1' => 'foo', 'idx2' => 'bar');
    
    echo json_encode($data);
    
    echo json_decode($data);
    

提交回复
热议问题