is JSON good or serialization good for data storage?

Source: Internet
Author: User
Keywords Php json serialization
For example, to put a product information (array representation, existing in Chinese) into the cookie, is the direct serialization or JSON storage?
What's the difference between the two?

Reply content:

For example, to put a product information (array representation, existing in Chinese) into the cookie, is the direct serialization or JSON storage?
What's the difference between the two?

Only strings can be stored in cookies, JSON objects cannot be stored, JSON serialization is stored

Experience shows that JSON can be used in JSON, speed, JSON faster than serialization, but some places must be serialized, such as the processing system session, cache and other places

JSON strings will be better than the serialization of space is less and JS can be used directly and conveniently.

For PHP, the related performance tests show that JSON serialization is faster than native serialization, and JSON is more versatile. The downside, perhaps, is that JSON cannot handle the serialization of PHP objects.

JSON should be selected from performance, length, and versatility
One sentence can be used without serialization of JSON
can use Msgpack without JSON

They're all saying json_encode performance is good. Actually this is related to the data you are dealing with and the PHP version.
However, it is recommended that JSON storage be more general and more semantic and more convenient to use.

Consider the easy-to-use line before considering performance.

Cheer up, you didn't make a book at the promotion meeting. I made a book to tell me that it is faster to store it in the form of a concatenation string than JSON. So you have to use splicing strings AH Pro.

JSON compatibility good, serialization speed see what you need

JSON is now a big advantage and cannot be serialized with JSON

If the individual PHP uses the proposed serialization, the serialization speed will be a little bit faster than Json_encode and Json_decode, and you can test it yourself. If you're not sure if only PHP is used (like cache, session, etc., PHP only), then use JSON.

  • 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.