Json2.js's use (Save IE)

Source: Internet
Author: User

Json2.js provides the JSON serialization (Json.stringify) and deserialization methods (Json.parse);
You can convert an object or array to a JSON string, or you can convert a JSON string into a JSON object.

Json2.js Source Address: Https://github.com/douglascrockford/JSON-js

Example of the last source network, use a look to understand,

The main explanation is

Json.stringify and Json.parse methods do not introduce json2.js under Ff,chrome, but in IE will error "json undefined", introduced json2.js resolution.

The string serialized by Json.stringify is received (PHP) on the server through Json_decode (str,true), and the second parameter, true, means to an array.

123<meta http-equiv="Content-type"Content="text/html; Charset=utf-8">4<title>json2</title>57<body>8<div id="msg"></div>9<div id="MSG2"></div>Ten<script src="Json2.js"Type="Text/javascript"></script> One<script type="Text/javascript"> A       varuser={
-UserName:"Zhang San", -Sex:"male" the      }; -      varStr=json.stringify (user); -document.getElementById ("msg"). innerhtml="Serialization:"+str; - +      varobj=json.parse (str); -document.getElementById ("MSG2"). innerhtml="deserialization:"+"Name:"+obj. UserName; +document.getElementById ("MSG2"). innerhtml+="&nbsp; Gender:"+obj. Sex; A</script> at</body> -

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.