ajax发送json字符窜,php解析json并返回的例子

ajax发送json字符窜,php解析json并返回的例子

ID:16502659

大小:138.00 KB

页数:6页

时间:2018-08-10

ajax发送json字符窜,php解析json并返回的例子_第1页
ajax发送json字符窜,php解析json并返回的例子_第2页
ajax发送json字符窜,php解析json并返回的例子_第3页
ajax发送json字符窜,php解析json并返回的例子_第4页
ajax发送json字符窜,php解析json并返回的例子_第5页
资源描述:

《ajax发送json字符窜,php解析json并返回的例子》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、前台AJAX发送JSON字符窜,PHP解析JSON并返回1.前台js用extjs框架发送//svaluearryAddAll是json对象要先转为字符串vartoJsonString=newNParser.JSON();varpostString=toJsonString.write(svaluearryAddAll,false);Ext.Ajax.request({url:'php/excel/test_excel.php',method:'post',success:function(response){a

2、lert(response.responseText);//window_inf(eval('('+response.responseText+')'));},failure:function(response){Ext.Msg.alert('连接失败',response.responseText);},params:{json:postString,cc:'123'}});1.后台php

3、ext/html;charset=utf-8");//header("Content-type:application/vnd.ms-excel");//header("Content-Disposition:filename=test.xls");$jsonString=$_POST['json'];//stripslashes清理反斜杆的,因为前台ajax发送时会自动为双引号单引号加上反斜杆!$json=stripslashes($jsonString);//把json字符串转为数组,true是数组,fal

4、se是转为对象$jsonArray=json_decode($json,true);//echo$jsonArray['layer'];//echo$jsonArray['sum'];echo$jsonArray['layer'];?>Json_encode(),json_decode()用法1.Json_encode(),把数组或者对象转为json格式的字符串$arr=array('a'=>www.zzarea.com,'b'=>"cc",'c'=>3,'d'=>4,'e'=>5);//数组$carray=j

5、son_encode($arr);echo$carray;//结果{"a":www.zzarea.com,"b":"cc","c":3,"d":4,"e":5}json字符串2.Json_decode(),把json字符串转为数组或者对象.其中Json_decode(a,b)有两个参数,第一个是,json字符串,第二个true或者false,当为true是返回一个数组,当为false是返回一个对象.$json1='{"layer":"aabb","properties":{"serial_id":"3"}}';

6、$jsonArray=json_decode($json1,true);//返回数组echo$jsonArray['layer'];//结果是aabb……………………………………………………………………………$json1='{"layer":"aabb","properties":{"serial_id":"3"}}';$jsonArray=json_decode($json1,false);//返回对象echo$jsonArray->layer;//结果是aabbPhp数组,能获取key和value的循环例子

7、1$arr1=array('a'=>1,'b'=>2);foreach($arr1as$key=>$value){echo$key.''.$value.'
';}例子2$a=array("one"=>1,"two"=>2,"three"=>3,"seventeen"=>17);foreach($aas$k=>$v){echo"$a[$k]=>$v".'
';

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。