(PHP 5 >= 5.2.0, PECL json >= 1.2.0)
json_decode — 对 JSON 格式的字符串进行编码
<?php
$json = ‘{“a”:1,”b”:2,”c”:3,”d”:4,”e”:5}’;
var_dump(json_decode($json));
var_dump(json_decode($json, true));
?>
以上例程会输出:
object(stdClass)#1 (5) {
[“a”] => int(1)
[“b”] => int(2)
[“c”] => int(3)
[“d”] => int(4)
[“e”] => int(5)
}
array(5) {
[“a”] => int(1)
[“b”] => int(2)
[“c”] => int(3)
[“d”] => int(4)
[“e”] => int(5)
}
底层代码:
<?php
$array = json_decode(safeJSON_chars($iso_8859_1_data));
function safeJSON_chars($data) {
$aux = str_split($data);
foreach($aux as $a) {
$a1 = urlencode($a);
$aa = explode(“%”, $a1);
foreach($aa as $v) {
if($v!=””) {
if(hexdec($v)>127) {
$data = str_replace($a,”&#”.hexdec($v).”;”,$data);
}
}
}
}
return $data;
}
?>
This is a test message.
转载请注明:苏demo的别样人生 » json_decode