Tools, FAQ, Tutorials:
What Is JavaScript JSON Object
What Is JavaScript JSON Object?
✍: FYIcenter.com
The JSON object is a built-in object in the JavaScript engine
that offers 2 functions to parse and generate JSON text strings:
1. JSON.parse() - Parses a text string from a JSON text string, constructs the JavaScript value. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
2. JSON.stringify() - Converts a JavaScript value to a JSON text string, An optional replacer function is specified to replace some values.
Here is a JavaScript code example, JSON-Hello.html, that shows you how to use the built-in JSON object:
<!-- JSON-Hello.html Copyright (c) FYIcenter.com --> <html> <body> <script type="text/javascript"> var object = {"msg":"Hello World!"}; var str = JSON.stringify(object); document.write("<p>JSON text string from JSON.stringify():</p>"); document.write("<pre>str = "+str+"</pre>"); var val = JSON.parse(str); document.write("<p>Value from JSON.parse():</p>"); document.write("<pre>val.msg = "+val.msg+"</pre>"); </script> </body> </html>
Open this example, JSON-Hello.html, in a Web browser. You see the following:
JSON text string from JSON.stringify(): str = {"msg":"Hello World!"} Value from JSON.parse(): val.msg = Hello World!
2017-08-16, 640👍, 0💬
Popular Posts:
What Is an HTML "em" Tag/Element? An "em" element is an inline element that you can use to specify t...
How to create Hello-3.0.epub with WinRAR? I have all required files to create Hello-3.0.epub. To cre...
What is Azure API Management Developer Portal Admin? The Developer Portal Admin is an Azure Web port...
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...