PHP代码
  1. <?php  
  2. //公共声明  
  3. header('Content-type: text/json');  
  4. html_entity_decode($string, ENT_QUOTES, 'UTF-8');  
  5.   
  6. //回调参数设置  
  7. $param="Jsoncallback";  
  8. $callback=$_REQUEST[$param];  
  9.   
  10. $students=array(  
  11.     array("风清扬","1101","23","52819911"),  
  12.     array("许志飞","1101","23","52819911"),  
  13.     array("令狐冲","1102","21","52819901"),  
  14.     array("任我行","1103","22","52819991"),  
  15.     array("任盈盈","1104","24","52819981"),  
  16.     array("东方不败","1105","26","52819981")  
  17. );  
  18. $tempBegin='<style>*{margin:0;padding:0;}h1{font-size:16px;text-align:center; line-height:45px;}body{color:#333;font-size:14px;font-family:"MicrosoftYahei";background:#B7CACC;}div{border:1px solid #405E7B; border-bottom:0; width:95%; margin:0 auto;background:#fff;content:"";display:table;clear:both}li{line-height:35px;list-style:none;width:25%;text-align:center;border-bottom:1px solid #405E7B;float:left;}</style><h1>最近风云人员名单</h1><div>';  
  19. foreach($students as $v){  
  20.     $tempBegin.='
  21.     <ul>
  22.         <li>'.$v[0].'</li>
  23.         <li>'.$v[1].'</li>
  24.         <li>'.$v[2].'</li>
  25.         <li>'.$v[3].'</li>
  26.     </ul>
  27.     ';  
  28. }  
  29. $tempEnd=$tempBegin.'</div>';  
  30. //echo $tempEnd;  
  31.   
  32. $str1=base64_encode($tempEnd);  
  33. $str2='{"dataList":"'.$str1.'"}';  
  34. $jsonStr=$callback."(".$str2.")";  
  35.   
  36. //判断请求参数存在就会输出Json数据  
  37. //if(isset($callback)&&!empty($callback)){  
  38. if(isset($callback)){  
  39.     echo $jsonStr;  
  40. }  
  41.   
  42. //判断请求参数不存在就输出错误信息  
  43. if(!isset($callback)){  
  44.     header("Content-type: text/html; charset=utf-8");  
  45.     $str="<h1>400 Required String parameter '{$param}' is not present</h1><hr /><small>http Request with error params: none callback function</small>";  
  46.     echo $str;  
  47. }  
  48.   
  49. ?>  
PHP/Java/Go | 评论(0) | 引用(0) | 阅读(3716)