ST 可以把数据包装成json式发送到php端 cartItemsStore = Ext.getStore('cartitemsconvert');var allData = [];cartItemsStore.each(function(records){allData.push(records.getData());});var dataToBeSentToServer = Ext.JSON.encode(allData);console.lo
ST 可以把数据包装成json格式发送到php端
cartItemsStore = Ext.getStore('cartitemsconvert'); var allData = []; cartItemsStore.each(function(records){ allData.push(records.getData()); }); var dataToBeSentToServer = Ext.JSON.encode(allData); console.log(dataToBeSentToServer);
Ext.data.JsonP.request({ url: 'http://londit-50c03e41547f8.com.1130.url-test.com/dingcan/php/save-orders.php', callbackKey: 'callback', params: { sendData:dataToBeSentToServer }, timeout:2000, success: function(result, request) { console.log('提交数据成功'); } });
$sendData = $_REQUEST['sendData']; <span>$jsondata = stripslashes($sendData);</span> //$sendData = '[{"id":"1","food":"\u5f20\u96ea\u6885","age":"27","subject":"\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f"},{"id":"2","food":"\u5f20\u6c9b\u9716","age":"21","subject":"\u8f6f\u4ef6\u5de5\u7a0b"}]'; $arrayData = json_decode($jsondata); foreach($arrayData as $obj){ echo "id:".$obj->food."<br>"; }
另外附上PHP两种解析json数据的方法:
在PHP代码中处理JSON 格式的字符串的两种方法:唯一不同已经highlight出来了
方法一:
$json ='[{"id":"1","name":"\u5f20\u96ea\u6885","age":"27","subject":"\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f"},{"id":"2","name":"\u5f20\u6c9b\u9716","age":"21","subject":"\u8f6f\u4ef6\u5de5\u7a0b"}]'; <span>$students = json_decode($json);//得到的是 object</span> foreach($students as $obj){ echo "姓名:".$obj->name."年龄:".$obj->age." 专业:".$obj->subject."<br>"; }
方法二:
$json ='[{"id":"1","name":"\u5f20\u96ea\u6885","age":"27","subject":"\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f"},{"id":"2","name":"\u5f20\u6c9b\u9716","age":"21","subject":"\u8f6f\u4ef6\u5de5\u7a0b"}]'; <span>$students = json_decode($json, </span><span>true</span><span>);//得到的是 array</span> for($i=0;$i<count echo></count>"; }