After the json-php array is serialized, the data cannot be deserialized.

Source: Internet
Author: User
I put an array serialized in MySQL, and then get it in PHP, sent in JSON format, the interface to accept this data, and then convert the JSON into an array, and finally found that the array product_list key to the corresponding serialized array can not be deserialized, What is this for?

    1. The product_list in a array is an array
    2. Serializing Product_list into a library
    3. PHP queries the database and converts the entire large array into JSON sent to the interface caller
      4. The requested interface put the JSON into an array, after successfully converting to an array, the product_list keys of the arrays are found, the corresponding
      The deserialization of the data conversion to an array failed

Reply content:

I put an array serialized in MySQL, and then get it in PHP, sent in JSON format, the interface to accept this data, and then convert the JSON into an array, and finally found that the array product_list key to the corresponding serialized array can not be deserialized, What is this for?

    1. The product_list in a array is an array
    2. Serializing Product_list into a library
    3. PHP queries the database and converts the entire large array into JSON sent to the interface caller
      4. The requested interface put the JSON into an array, after successfully converting to an array, the product_list keys of the arrays are found, the corresponding
      The deserialization of the data conversion to an array failed

It may be because of the Chinese encoding. PHP is dependent on byte length when deserializing.
Do not use PHP serialization to be stored in, turn into JSON, so much more versatile. Who can guarantee that this data is always read by PHP?

I have ever encountered a situation where the same string, the result of my local serialization, is not the same as the result of the serial number on the remote server. I didn't delve into it because it didn't affect my system. But I know there's a phenomenon that can happen:

Perhaps because of the PHP version of the problem, perhaps because of the problem of PHP extension, and perhaps because of coding and so on for some reason, in different server environments, the result of PHP serialization is unstable 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.