Tools, FAQ, Tutorials:
JSON-parse.html - JSON.parse() Example Code
Where to get a JSON.parse() Example Code in JavaScript?
✍: FYIcenter.com
Here is a good JSON.parse() example code in JavaScript.
<!-- JSON-parse.html
Copyright (c) FYIcenter.com
-->
<html>
<body>
<script type="text/javascript">
var val1 = JSON.parse('2020'); // A number value
var val2 = JSON.parse('"foo"'); // A string value
var val3 = JSON.parse('true'); // A Boolean value
var val4 = JSON.parse('null'); // A null
var val5 = JSON.parse('[1, 5, "false"]'); // An array
var val6 = JSON.parse('{}'); // An empty Object
var val7 = JSON.parse('{"msg": "Hi!"}'); // An Object
document.write("<p>Value from JSON.parse():</p>");
document.write("<pre>");
document.write(" val1.toString() = "+val1.toString()+"\n");
document.write(" val2.toString() = "+val2.toString()+"\n");
document.write(" val3.toString() = "+val3.toString()+"\n");
document.write(" val5.toString() = "+val5.toString()+"\n");
document.write(" val6.toString() = "+val6.toString()+"\n");
document.write(" val7.toString() = "+val7.toString()+"\n");
document.write("</pre>");
</script>
</body>
</html>
Save the above code in a file, JSON-parse.html, and open it in a Web browser. You see the following output:
Value from JSON.parse(): val1.toString() = 2020 val2.toString() = foo val3.toString() = true val4 = null val5.toString() = 1,5,false val6.toString() = [object Object] val7.toString() = [object Object]
⇒ JSON-parse-Error.html - JSON.parse() Errors
2023-04-13, ∼2126🔥, 0💬
Popular Posts:
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to use the "set-backend-service" Policy Statement for an Azure API service operation? The "set-b...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...