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


Register Now >

Starter Package

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

Get Started >

Alibaba Cloud Free Trial


Learn more >

Contact Us

