三個(gè)函數(shù)
json_encode():對(duì)變量進(jìn)行JSON編碼
json_decode():對(duì)JSON格式的字符串進(jìn)行編碼轉(zhuǎn)為PHP變量
son_last_error():返回最后的編碼或解碼過程發(fā)生的錯(cuò)誤
參數(shù)
JSON_PRETTY_PRINT:打印輸出json的格式
JSON_FOECE_OBJECT:轉(zhuǎn)換成對(duì)象
JSON_UNESCAPED_SLASHES
實(shí)例
<?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);
?>