三个函数
json_encode():对变量进行JSON编码
json_decode():对JSON格式的字符串进行编码转为PHP变量
son_last_error():返回最后的编码或解码过程发生的错误
参数
JSON_PRETTY_PRINT:打印输出json的格式
JSON_FOECE_OBJECT:转换成对象
JSON_UNESCAPED_SLASHES
实例
<?php
header("Content-Type: application/json");
$str = <<< ETO
"json字符串"
ETO;
$obj = json_decode($str,true);
$response;
$strCount = count($obj['tList']);
$index = $_REQUEST['index'];
$length = $_REQUEST['length'];
if($index < 0 || $index > $strCount){
echo json_encode($response);
exit(0);
}
if ($length < 0) {
echo json_encode($response);
exit(0);
}
for ($i = $index; $i < ($index + $length) && $i < $strCount; $i++){
$response[] = $obj['tList'][$i];
}
echo json_encode($response);
?>