服务端得到一段json数据 我想把json数据转换为数组 但 5.2以下版本的php不支持 json_decode()函数
求解决办法
------解决方案--------------------
可以自已循环拼接啊!
------解决方案--------------------
帮你找了段,凑合用吧
- PHP code
function _json_decode($json){ $comment = false; $out = '$x='; for ($i=0; $i<strlen($json);$i++){ if (!$comment){ if (($json[$i] == '{') || ($json[$i] == '[')) $out .= ' array('; else if (($json[$i] == '}') || ($json[$i] == ']')) $out .= ')'; else if ($json[$i] == ':') $out .= '=>'; else $out .= $json[$i]; }else $out .= $json[$i]; if($json[$i]== '"' && $json[($i-1)]!="\\") $comment = !$comment; } eval($out.';'); return $x; } $json='{"name":"hello world!","arr":[1,2,3,4]}'; print_r(_json_decode($json));