es5 JSON objects

1. JSON.stringify(obj/arr)

js objects (array) is converted to json objects (array)

2. JSON.parse(json)

json objects (array) is converted to js objects (array)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        " Use strict " 
        // 1. the JSON.stringify (obj / ARR)
         //     // the JS json objects converted to an array of objects (array)
         // 2. the JSON.parse (json)
         //     json objects into object array js

        var obj = { usernanme: 'kobe' }
        obj = JSON.stringify(obj)//json对象
        console.log(typeof obj)//string

        obj = JSON.parse(obj);   //js 对象
        console.log(typeof obj)//object

      
      var A = ' fddsf ' 
      var B = " dsdffds " 
      // ordinary arrays

    </script>

</body>

</html>

 

Guess you like

Origin www.cnblogs.com/hack-ing/p/12005296.html