An error occurred while saving JSON data to the SESSION.

Source: Internet
Author: User
Save the JSON data to the JSON data transmitted by the client when the SESSION fails:
[{"Category_id": 0, "category_products": [[{"para_name": "brand", "para_val": "haifesi" },{ "para_name ": "Production date", "para_val": "2015-08-11"}], [{"para_name": "brand", "para_val": "New Silk Road" },{ "para_name ": "Production date", "para_val": "2015-08-11" },{ "para_name": "applicable hair", "para_val ": "Dry, hairy, oily hair"}]}, {"category_id": 1, "category_products": [[{"para_name": "brand", "para_val ": "Pan Ting" },{ "para_name": "production date", "para_val": "2015-06-11"}]

The data obtained after serialization and deserialization is different from the above data! What should I do? This is the data obtained after deserialization in PHP:
A: 2: {I: 0; O: 8: "stdClass": 2: {s: 11: "category_id"; I: 0; s: 17: "category_products "; a: 2: {I: 0; a: 2: {I: 0; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 6: "brand"; s: 8: "para_val"; s: 9: "haifeisi";} I: 1; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 12: "production date"; s: 8: "para_val"; s: 10: "2015-08-11" ;}} I: 1;: 3: {I: 0; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 6: "brand"; s: 8: "para_val"; s: 9: "";} I: 1; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 12: "Production date"; s: 8: "para_val"; s: 10: "2015-08-11";} I: 2; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 12: "applicable hair"; s: 8: "para_val"; s: 30: "dry, hairy, oily hair ";}}}} i: 1; O: 8: "stdClass": 2: {s: 11: "category_id"; I: 1; s: 17: "category_products"; a: 1: {I: 0; a: 2: {I: 0; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 6: "brand"; s: 8: "para_val"; s: 6: "Pan Ting";} I: 1; O: 8: "stdClass": 2: {s: 9: "para_name"; s: 12: "production date"; s: 8: "para_val"; s: 10: "2015-06-11 ";}}}}}


Reply to discussion (solution)

Your second data is serialized.

Your second data is serialized.


I tried it. it is true that this will happen if there is no deserialization.
However, I want to output the data to the client again after deserialization and return json through Ajax. I will use json_encode deserialization again through the console. log is returned to [object]. Is this normal?

I don't know your application scenarios
Your first data segment is a json string and will not be serialized into the second data segment.

It is correct to convert console. log to [object ].

Stdclass indicates that you performed the json_decode ($ json, 1) next to the returned json.
Of course, the next urlcode is yours.

Ps: why do we need to do this? decode encode directly serializes the deserialization.

I don't know your application scenarios
Your first data segment is a json string and will not be serialized into the second data segment.

It is correct to convert console. log to [object ].


After obtaining the original JSON string on the server side, I use json_decode to convert the JSON string into an array object, serialize the array object, and assign the value to the $ _ SESSION variable. This is because my data is of two levels and the number is not fixed. Background input interface similar to Baidu Experience. Therefore, I use json to transmit front-end and back-end data. before the final content is released, I first store the data in the SESSION, and no addition, deletion, modification, or query will be performed by the database (this method has been tried, it is very difficult to add, delete, modify, and query data because the data is associated with a two-layer structure ).
I wonder if this approach is appropriate. Is there a better solution?

There is no need for serialization. just store the data directly into the session.

I don't know your application scenarios
Your first data segment is a json string and will not be serialized into the second data segment.

It is correct to convert console. log to [object ].



Front-end interface operations



Is there a better solution?


There is no need for serialization. just store the data directly into the session.



GOOD! Serialization is not required. Thank You!

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.