Conversion of JSON and string

Source: Internet
Author: User

Although I am mainly studying. net, it is annoying that the hateful school is not forced to learn JSP.
When I was writing JSP today, I suddenly wanted to use the Ajax framework of MS with servlet to implement Ajax effect in JSP. There was a small problem in the middle:

In the servlet, the output using out. Print is a string. When you want to transmit multiple values, JSON is used. But how does the JSON string become an object after arriving at the room end?
After multiple experiments, the following methods are obtained:
VaR STR = "{ID: True, value: '1 '}";
VaR OBJ = eval ('+ STR + ')');
In this way, you can directly call: obj. ID obj. value.

On the contrary, if JSON is converted to string, you only need to use for to traverse the attributes and attribute values of the object and splice the strings. Time relationship. This function will not be written for the moment. Write it again. Hey.

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.