JSON is usually used to exchange data with the server.

JSON.parse() syntax

When receiving server data, it is usually a string.

We can use the JSON.parse() method to convert data into JavaScript objects.

JSON.parse() example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php.cn</title>
</head>
<body>

<h2>从 JSON 对象中创建 JavaScript 对象</h2>

<p id="demo"></p>

<script>
var obj = JSON.parse('{ "name":"php.cn", "alexa":10000, "site":"m.sbmmt.com" }');
document.getElementById("demo").innerHTML = obj.name + ":" + obj.site;
</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance