{"id":382,"date":"2020-02-04T23:32:00","date_gmt":"2020-02-04T15:32:00","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=382"},"modified":"2020-02-04T23:32:00","modified_gmt":"2020-02-04T15:32:00","slug":"json","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/04\/json\/","title":{"rendered":"JSON"},"content":{"rendered":"<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta charset=\"UTF-8\"&gt;\n\t\t&lt;title&gt;&lt;\/title&gt;\n\t\t\n\t\t&lt;!--\n\t\t\t\u5982\u679c\u9700\u8981\u517c\u5bb9IE7\u53ca\u4ee5\u4e0b\u7684JSON\u64cd\u4f5c\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u5f15\u5165\u4e00\u4e2a\u5916\u90e8\u7684js\u6587\u4ef6\u6765\u5904\u7406\n\t\t--&gt;\n\t\t&lt;script type=\"text\/javascript\" src=\"js\/json2.js\"&gt;&lt;\/script&gt;\n\t\t&lt;script type=\"text\/javascript\"&gt;\n\t\t\t\n\t\t\t\/*\n\t\t\t * JSON\n\t\t\t * \t- JS\u4e2d\u7684\u5bf9\u8c61\u53ea\u6709JS\u81ea\u5df1\u8ba4\u8bc6\uff0c\u5176\u4ed6\u7684\u8bed\u8a00\u90fd\u4e0d\u8ba4\u8bc6\n\t\t\t * \t- JSON\u5c31\u662f\u4e00\u4e2a\u7279\u6b8a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53ef\u4ee5\u88ab\u4efb\u610f\u7684\u8bed\u8a00\u6240\u8bc6\u522b\uff0c\n\t\t\t * \t\t\u5e76\u4e14\u53ef\u4ee5\u8f6c\u6362\u4e3a\u4efb\u610f\u8bed\u8a00\u4e2d\u7684\u5bf9\u8c61\uff0cJSON\u5728\u5f00\u53d1\u4e2d\u4e3b\u8981\u7528\u6765\u6570\u636e\u7684\u4ea4\u4e92\n\t\t\t * \t- JSON\n\t\t\t * \t\t- JavaScript Object Notation JS\u5bf9\u8c61\u8868\u793a\u6cd5\n\t\t\t * \t\t- JSON\u548cJS\u5bf9\u8c61\u7684\u683c\u5f0f\u4e00\u6837\uff0c\u53ea\u4e0d\u8fc7JSON\u5b57\u7b26\u4e32\u4e2d\u7684\u5c5e\u6027\u540d\u5fc5\u987b\u52a0\u53cc\u5f15\u53f7\n\t\t\t * \t\t\t\u5176\u4ed6\u7684\u548cJS\u8bed\u6cd5\u4e00\u81f4\n\t\t\t * \t\tJSON\u5206\u7c7b\uff1a\n\t\t\t * \t\t\t1.\u5bf9\u8c61 {}\n\t\t\t * \t\t\t2.\u6570\u7ec4 []\n\t\t\t * \n\t\t\t * \t\tJSON\u4e2d\u5141\u8bb8\u7684\u503c\uff1a\n\t\t\t * \t\t\t1.\u5b57\u7b26\u4e32\n\t\t\t * \t\t\t2.\u6570\u503c\n\t\t\t * \t\t\t3.\u5e03\u5c14\u503c\n\t\t\t * \t\t\t4.null\n\t\t\t * \t\t\t5.\u5bf9\u8c61\n\t\t\t * \t\t\t6.\u6570\u7ec4\n\t\t\t *\/\n\t\t\t\n\t\t\t\/\/\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\n\t\t\t\n\t\t\t\n\t\t\tvar arr = '[1,2,3,\"hello\",true]';\n\t\t\t\n\t\t\tvar obj2 = '{\"arr\":[1,2,3]}';\n\t\t\t\n\t\t\tvar arr2 ='[{\"name\":\"\u5b59\u609f\u7a7a\",\"age\":18,\"gender\":\"\u7537\"},{\"name\":\"\u5b59\u609f\u7a7a\",\"age\":18,\"gender\":\"\u7537\"}]';\n\t\t\t\n\t\t\t\/*\n\t\t\t * \u5c06JSON\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3aJS\u4e2d\u7684\u5bf9\u8c61\n\t\t\t * \t\u5728JS\u4e2d\uff0c\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5de5\u5177\u7c7b\uff0c\u5c31\u53ebJSON\n\t\t\t * \t\u8fd9\u4e2a\u5bf9\u8c61\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5c06\u4e00\u4e2aJSON\u8f6c\u6362\u4e3aJS\u5bf9\u8c61\uff0c\u4e5f\u53ef\u4ee5\u5c06\u4e00\u4e2aJS\u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\n\t\t\t *\/\n\t\t\t\n\t\t\tvar json = '{\"name\":\"\u5b59\u609f\u7a7a\",\"age\":18,\"gender\":\"\u7537\"}';\n\t\t\t\n\t\t\t\/*\n\t\t\t * json --&gt; js\u5bf9\u8c61\n\t\t\t * \t JSON.parse()\n\t\t\t * \t\t- \u53ef\u4ee5\u5c06\u4ee5JSON\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3ajs\u5bf9\u8c61\n\t\t\t * \t\t- \u5b83\u9700\u8981\u4e00\u4e2aJSON\u5b57\u7b26\u4e32\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f1a\u5c06\u8be5\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3aJS\u5bf9\u8c61\u5e76\u8fd4\u56de\n\t\t\t *\/\n\t\t\t\n\t\t\tvar o = JSON.parse(json);\n\t\t\tvar o2 = JSON.parse(arr);\n\t\t\t\n\t\t\tconsole.log(o);\n\t\t\t\/\/console.log(o2[1]);\n\t\t\t\n\t\t\tvar obj3 = {name:\"\u732a\u516b\u6212\" , age:28 , gender:\"\u7537\"};\n\t\t\tvar xxx = '\"'+obj3+'\"';\n\t\t\tconsole.log(xxx);\n\t\t\t\n\t\t\t\/*\n\t\t\t * JS\u5bf9\u8c61 ---&gt; JSON\n\t\t\t * \tJSON.stringify()\n\t\t\t * \t\t- \u53ef\u4ee5\u5c06\u4e00\u4e2aJS\u5bf9\u8c61\u8f6c\u6362\u4e3aJSON\u5b57\u7b26\u4e32\n\t\t\t * \t\t- \u9700\u8981\u4e00\u4e2ajs\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2aJSON\u5b57\u7b26\u4e32\n\t\t\t *\/\n\t\t\t\n\t\t\tvar str = JSON.stringify(obj3);\n\t\t\tconsole.log(str);\n\t\t\t\n\t\t\t\/*\n\t\t\t * JSON\u8fd9\u4e2a\u5bf9\u8c61\u5728IE7\u53ca\u4ee5\u4e0b\u7684\u6d4f\u89c8\u5668\u4e2d\u4e0d\u652f\u6301\uff0c\u6240\u4ee5\u5728\u8fd9\u4e9b\u6d4f\u89c8\u5668\u4e2d\u8c03\u7528\u65f6\u4f1a\u62a5\u9519\n\t\t\t *\/\n\t\t\t\n\t\t\t\n\t\t\tvar str3 = '{\"name\":\"\u5b59\u609f\u7a7a\",\"age\":18,\"gender\":\"\u7537\"}';\n\t\t\t\n\t\t\tJSON.parse(str3);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t&lt;\/script&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta charset=\"UTF-8\"&gt;\n\t\t&lt;title&gt;&lt;\/title&gt;\n\t\t&lt;script type=\"text\/javascript\"&gt;\n\t\t\n\t\t\tvar str = '{\"name\":\"\u5b59\u609f\u7a7a\",\"age\":18,\"gender\":\"\u7537\"}';\n\t\t\t\n\t\t\t\/*\n\t\t\t * eval()\n\t\t\t * \t- \u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u6267\u884c\u4e00\u6bb5\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684JS\u4ee3\u7801\uff0c\u5e76\u5c06\u6267\u884c\u7ed3\u679c\u8fd4\u56de\n\t\t\t * \t- \u5982\u679c\u4f7f\u7528eval()\u6267\u884c\u7684\u5b57\u7b26\u4e32\u4e2d\u542b\u6709{},\u5b83\u4f1a\u5c06{}\u5f53\u6210\u662f\u4ee3\u7801\u5757\n\t\t\t * \t\t\u5982\u679c\u4e0d\u5e0c\u671b\u5c06\u5176\u5f53\u6210\u4ee3\u7801\u5757\u89e3\u6790\uff0c\u5219\u9700\u8981\u5728\u5b57\u7b26\u4e32\u524d\u540e\u5404\u52a0\u4e00\u4e2a()\n\t\t\t * \n\t\t\t * \t- eval()\u8fd9\u4e2a\u51fd\u6570\u7684\u529f\u80fd\u5f88\u5f3a\u5927\uff0c\u53ef\u4ee5\u76f4\u63a5\u6267\u884c\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684js\u4ee3\u7801\uff0c\n\t\t\t * \t\t\u4f46\u662f\u5728\u5f00\u53d1\u4e2d\u5c3d\u91cf\u4e0d\u8981\u4f7f\u7528\uff0c\u9996\u5148\u5b83\u7684\u6267\u884c\u6027\u80fd\u6bd4\u8f83\u5dee\uff0c\u7136\u540e\u5b83\u8fd8\u5177\u6709\u5b89\u5168\u9690\u60a3\n\t\t\t *\/\n\t\t\t\n\t\t\tvar str2 = \"alert('hello');\";\n\t\t\t\n\t\t\tvar obj = eval(\"(\"+str+\")\");\n\t\t\t\n\t\t\t\/\/console.log(obj);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t&lt;\/script&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset= &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[4],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/382"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=382"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}