After arrays in json-PHP are serialized, the data cannot be deserialized.

Source: Internet
Author: User
I serialized an array into MySQL and sent it in JSON format after it was obtained using PHP. When the interface accepts the data, the JSON is converted to an array, finally, we found that the serialization array corresponding to the product_list key of this array cannot be deserialized. Why ?... I serialized an array into MySQL and sent it in JSON format after it was obtained using PHP. When the interface accepts the data, the JSON is converted to an array, finally, we found that the serialization array corresponding to the product_list key of this array cannot be deserialized. Why?

  1. The product_list in array A is an array.
  2. Serialize product_list to database
  3. PHP queries the database and converts the entire large array to JSON and sends it to the interface caller.
    4. The requested interface converts JSON to an array. After the array is successfully converted, The product_list key of the array is found, corresponding
    Failed to convert the deserialization data to an array.

Reply content:

I serialized an array into MySQL and sent it in JSON format after it was obtained using PHP. When the interface accepts the data, the JSON is converted to an array, finally, we found that the serialization array corresponding to the product_list key of this array cannot be deserialized. Why?

  1. The product_list in array A is an array.
  2. Serialize product_list to database
  3. PHP queries the database and converts the entire large array to JSON and sends it to the interface caller.
    4. The requested interface converts JSON to an array. After the array is successfully converted, The product_list key of the array is found, corresponding
    Failed to convert the deserialization data to an array.

It may be because of Chinese encoding. Php deserialization depends on the length of bytes.
Do not use php serialization to save it into json, which is more universal. Who can ensure that the data is always read by php?

I have encountered such a situation where the serial number of the same string in my local serialization is different from that on the remote server. Because it does not affect my system, I did not go into details. But I know this happens:

It may be because of the php version, the php extension, or the encoding,In different server environments, PHP serialization results are unstable and unreliable..

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.