How JSON data formats are used

Source: Internet
Author: User
Tags format array json string variable

Json_encode () JSON encoding a variable
Json_decode () decodes a JSON-formatted string into a PHP variable
Json_last_error returns the last occurrence of the error

Resource types cannot be converted to JSON format or converted to serialize data format, similar to the identity of a file.

the similarities and differences of JSON data format and serialize data format
Same point
1. Convert other data types into a string that can be transmitted
2, are the structural data
Different points
1, serialize serialized data format to save the original type of data
2, JSON data format to be more concise than the data format after serialize serialization
Usage scenarios:
1, JSON is suitable for large amount of data, do not require the retention of the original data type use
2, serialize suitable for storing data strings with encryption, to prevent the interception of data in the middle of the deserialization of the break

  1. Header ("content-type:text/html;  Charset=utf-8 "); Statement code
  2. function Createhtmltag ($tag = "") {
  3. echo "$tag
    ";
  4. }
  5. Createhtmltag ("Www.aseoe.Com");
  6. Createhtmltag ("JSON and serialize contrast");
  7. $member = Array ("Site", "Tree"); Define an array
  8. Var_dump ($member); Print
  9. $JSONOBJ = Json_encode ($member); Parse into JSON data format
  10. $SERIALIZEOBJ = serialize ($member); Parsing into Serialize data format
  11. Createhtmltag ($JSONOBJ); No need to save data format
  12. Createhtmltag ($SERIALIZEOBJ); Can encrypt the transmitted data to prevent interception
  13. ?>




Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.