PHP代码
- <?php
- //公共声明
- header('Content-type: text/json');
- html_entity_decode($string, ENT_QUOTES, 'UTF-8');
- //回调参数设置
- $param="callbackAA";
- $callback=$_REQUEST[$param];
- $str = '{"topNew":{"specialType":245,"title":"宝宝该由谁来带","img":"http://photo.zastatic.com/photo/activity/1397451753098.jpg","url":"http://t.zhenai.com/vote/voteindex.do?specialType=244&fromMainPage=1","count":23105},"topTwo":[{"specialType":173,"title":"让疯狂眼球帮你搞定爱情","img":"http://photo.zastatic.com/photo/activity/1386918466579.jpg","url":"http://t.zhenai.com/activity/carzyEyes.do?source=0&fromMainPage=2","count":3121},{"specialType":104,"title":"你问我爱你有多深 聘礼代表我的心","img":"http://photo.zastatic.com/photo/activity/1373638053176.jpg","url":"http://t.zhenai.com/activity/brideprice.do?source=3&fromMainPage=3","count":351005}]}';
- //自造Json数据
- $str2='[{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":25,"name":"男士","province":"上海","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":"186****1046"},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"200元的爱玛电动车代金券","mobile":"186****1046"},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"河南","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"1","photoPath":"/201412/11/11/49/1418269782350A03EA57_c.jpg"},"age":20,"name":"白日做梦","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""}]';
- $str = $callback . "(" .$str2.")";
- //判断存在参数才输出
- if(isset($callback)&&!empty($callback)){
- echo $str;
- }
- //判断参数是否为空,提示默认信息
- if(empty($callback)){
- header("Content-type: text/html; charset=utf-8");
- $str="<h1>400 Required String parameter '{$param}' is not present</h1><hr /><small>http Request with error params</small>";
- echo $str;
- }
- ?>
最终更新:
PHP代码
- <?php
- //公共声明
- header('Content-type: text/json');
- html_entity_decode($string, ENT_QUOTES, 'UTF-8');
- //回调参数设置
- $param="callbackAA";
- $callback=$_REQUEST[$param];
- $str = '{"topNew":{"specialType":245,"title":"宝宝该由谁来带","img":"http://photo.zastatic.com/photo/activity/1397451753098.jpg","url":"http://t.zhenai.com/vote/voteindex.do?specialType=244&fromMainPage=1","count":23105},"topTwo":[{"specialType":173,"title":"让疯狂眼球帮你搞定爱情","img":"http://photo.zastatic.com/photo/activity/1386918466579.jpg","url":"http://t.zhenai.com/activity/carzyEyes.do?source=0&fromMainPage=2","count":3121},{"specialType":104,"title":"你问我爱你有多深 聘礼代表我的心","img":"http://photo.zastatic.com/photo/activity/1373638053176.jpg","url":"http://t.zhenai.com/activity/brideprice.do?source=3&fromMainPage=3","count":351005}]}';
- //自造Json数据
- $str2='[{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":25,"name":"男士","province":"上海","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":"186****1046"},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"200元的爱玛电动车代金券","mobile":"186****1046"},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"河南","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"0","photoPath":"/resources/v20/images/boy.png"},"age":24,"name":"男士","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""},{"icon":{"hasPhoto":"1","photoPath":"/201412/11/11/49/1418269782350A03EA57_c.jpg"},"age":20,"name":"白日做梦","province":"北京","lottery":"100元的爱玛电动车代金券","mobile":""}]';
- $str=$callback."(".$str2.")";
- //判断请求参数存在就会输出Json数据
- if(isset($callback)){
- echo $str;
- }
- //判断请求参数不存在就输出错误信息
- if(!isset($callback)){
- header("Content-type: text/html; charset=utf-8");
- $str="<h1>400 Required String parameter '{$param}' is not present</h1><hr /><small>http Request with error params: none callback function</small>";
- echo $str;
- }
- ?>