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?
- The product_list in array A is an array.
- Serialize product_list to database
- 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?
- The product_list in array A is an array.
- Serialize product_list to database
- 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..