How does Senchatouch and PHP parse json data?

Source: Internet
Author: User
ST can package the data into json and send it to the php side cartItemsStoreExt. getStore (cartitemsconvert); varallData []; cartItemsStore. each (function (records) {allData. push (records. getData () ;}); vardataToBeSentToServerExt. JSON. encode (allData); console. lo

ST can package data in json format and send it to cartItemsStore = Ext. getStore ('cartitemsconvert'); var allData = []; cartItemsStore. each (function (records) {allData. push (records. getData () ;}); var dataToBeSentToServer = Ext. JSON. encode (allData); console. lo

ST can package the data into json format and send it to the php end.

cartItemsStore = Ext.getStore('cartitemsconvert');var allData = [];cartItemsStore.each(function(records){allData.push(records.getData());});var dataToBeSentToServer = Ext.JSON.encode(allData);console.log(dataToBeSentToServer);

Then use jsonp or ajax to transmit data to the PHP end.
Ext. data. jsonP. request ({url: 'http: // callback, callbackKey: 'callback', params: {sendData: dataToBeSentToServer}, timeout: 2000, success: function (result, request) {console. log ('data submitted successfully ');}});

Then how does PHP obtain the json data? The red part is a php issue. If the stripslashes conversion is not required. The stripslashes () function deletes the backslash added by the addslashes () function. Otherwise, The data is printed out empty. Another solution is: The fix was to turn off magic_quotes in php. ini. if you do this, you will no longer need the call to stripslashes ().
$sendData = $_REQUEST['sendData'];$jsondata = stripslashes($sendData);//$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."
";}

Two Methods for parsing json data are attached to PHP:

There are two methods to process JSON strings in PHP code: the only difference is that highlight has come out.

Method 1:

$ 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"}] '; $ students = json_decode ($ json); // The objectforeach ($ students as $ obj) {echo "name :". $ obj-> name. "Age :". $ obj-> age. "Major :". $ obj-> subject."
";}


Method 2:

$ 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"}] '; $ students = json_decode ($ json, true); // arrayfor ($ I = 0; $ I
 ";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.