{"id":2861,"date":"2016-09-18T13:28:32","date_gmt":"2016-09-18T05:28:32","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2861"},"modified":"2016-09-18T13:28:32","modified_gmt":"2016-09-18T05:28:32","slug":"%e5%9c%a8ajax%e4%b8%ad%e4%bd%bf%e7%94%a8jquery%e8%a7%a3%e6%9e%90%e8%bf%94%e5%9b%9e%e7%9a%84json%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2861.html","title":{"rendered":"\u5728Ajax\u4e2d\u4f7f\u7528jQuery\u89e3\u6790\u8fd4\u56de\u7684json\u5bf9\u8c61"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>\u7f18\u7531\uff1a<\/h5>\n<p>\u524d\u7aef\u65b0\u624b\u5b66\u4e60\u3001\u6574\u7406\u4e00\u4e9b\u7b80\u5355\u7684JavaScript\u77e5\u8bc6\uff0c\u65b9\u4fbf\u4ee5\u540e\u53c2\u8003\u3002<\/p>\n<h4>\u6b63\u6587\uff1a<\/h4>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h6>1.JSON.stringify()<\/h6>\n<pre class=\"lang:default decode:true\">console.log(JSON.stringify(response));  # \u4f7f\u7528 JSON.stringify \u5c06json\u5bf9\u8c61\u89e3\u6790\u6210\u5b57\u7b26\u4e32\nconsole.log(JSON.stringify(response, null, 2)); # pretty-print<\/pre>\n<h6>\u5982\u4f55\u5c06JSON.stringify()\u7684\u8f93\u51fa\u4f18\u96c5\u7684\u6253\u5370\u5728\u4e00\u4e2adiv\u4e2d\uff1f<\/h6>\n<p>\u5c06\u89e3\u6790\u540e\u7684\u5185\u5bb9\u653e\u5728 &lt;pre&gt; \u6807\u7b7e\u5185\u5373\u53ef\u3002\u53c2\u8003\uff1a<a href=\"http:\/\/stackoverflow.com\/questions\/16862627\/json-stringify-output-to-div-in-pretty-print-way\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/16862627\/json-stringify-output-to-div-in-pretty-print-way<\/a>\u3002<\/p>\n<h6>2.JSON.parse()<\/h6>\n<pre class=\"lang:default decode:true\">var data = JSON.parse(response);    # \u4f7f\u7528 JSON.parse \u5c06\u5bf9\u8c61\u89e3\u6790\u6210JavaScript\u5bf9\u8c61\nconsole.log(data);<\/pre>\n<h6>3.jQuery.parseJSON()<\/h6>\n<pre class=\"lang:default decode:true  \">jQuery.parseJSON()\u51fd\u6570\u7528\u4e8e\u5c06\u683c\u5f0f\u5b8c\u597d\u7684JSON\u5b57\u7b26\u4e32\u8f6c\u4e3a\u4e0e\u4e4b\u5bf9\u5e94\u7684JavaScript\u5bf9\u8c61\u3002\n\n\u6240\u8c13\"\u683c\u5f0f\u5b8c\u597d\"\uff0c\u5c31\u662f\u8981\u6c42\u6307\u5b9a\u7684\u5b57\u7b26\u4e32\u5fc5\u987b\u7b26\u5408\u4e25\u683c\u7684JSON\u683c\u5f0f\uff0c\u4f8b\u5982\uff1a\u5c5e\u6027\u540d\u79f0\u5fc5\u987b\u52a0\u53cc\u5f15\u53f7\u3001\u5b57\u7b26\u4e32\u503c\u4e5f\u5fc5\u987b\u7528\u53cc\u5f15\u53f7\u3002\n\n\u5982\u679c\u4f20\u5165\u4e00\u4e2a\u683c\u5f0f\u4e0d\"\u5b8c\u597d\"\u7684JSON\u5b57\u7b26\u4e32\u5c06\u629b\u51fa\u4e00\u4e2aJS\u5f02\u5e38\uff0c\u4f8b\u5982\uff1a\u4ee5\u4e0b\u5b57\u7b26\u4e32\u5747\u7b26\u5408JSON\u683c\u5f0f\uff0c\u4f46\u5b83\u4eec\u4e0d\u662f\u683c\u5f0f\u5b8c\u597d\u7684JSON\u5b57\u7b26\u4e32(\u56e0\u6b64\u4f1a\u629b\u51fa\u5f02\u5e38)\uff1a\n\/\/ \u4ee5\u4e0b\u5747\u662f\u5b57\u7b26\u4e32\u503c\uff0c\u7701\u7565\u4e86\u4e24\u4fa7\u7684\u5f15\u53f7\uff0c\u4ee5\u4fbf\u4e8e\u5c55\u73b0\u5185\u5bb9\n\n{id: 1} \/\/ id\u662f\u5c5e\u6027\u540d\u79f0\uff0c\u5fc5\u987b\u52a0\u53cc\u5f15\u53f7\n{'id': 1} \/\/ id\u662f\u5c5e\u6027\u540d\u79f0\uff0c\u5fc5\u987b\u7528\u53cc\u5f15\u53f7(\u4e0d\u80fd\u7528\u5355\u5f15\u53f7)\n{\"name\": 'CodePlayer'} \/\/ name\u5c5e\u6027\u7684\u503c\u662f\u5b57\u7b26\u4e32\uff0c\u5fc5\u987b\u7528\u53cc\u5f15\u53f7(\u4e0d\u80fd\u7528\u5355\u5f15\u53f7)<\/pre>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/17364091\/parse-json-response-using-jquery\">http:\/\/stackoverflow.com\/questions\/17364091\/parse-json-response-using-jquery<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/14478127\/parse-json-response-got-from-ajax-request-through-javascript\">http:\/\/stackoverflow.com\/questions\/14478127\/parse-json-response-got-from-ajax-request-through-javascript<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/17496348\/jquery-parse-json-on-ajax-success\">http:\/\/stackoverflow.com\/questions\/17496348\/jquery-parse-json-on-ajax-success<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/4162749\/convert-js-object-to-json-string\">http:\/\/stackoverflow.com\/questions\/4162749\/convert-js-object-to-json-string<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/4810841\/how-can-i-pretty-print-json-using-javascript\">http:\/\/stackoverflow.com\/questions\/4810841\/how-can-i-pretty-print-json-using-javascript<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/2614862\/how-can-i-beautify-json-programmatically\">http:\/\/stackoverflow.com\/questions\/2614862\/how-can-i-beautify-json-programmatically<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3515523\/javascript-how-to-generate-formatted-easy-to-read-json-straight-from-an-object\">http:\/\/stackoverflow.com\/questions\/3515523\/javascript-how-to-generate-formatted-easy-to-read-json-straight-from-an-object<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/16862627\/json-stringify-output-to-div-in-pretty-print-way\">http:\/\/stackoverflow.com\/questions\/16862627\/json-stringify-output-to-div-in-pretty-print-way<\/a><\/li>\n<li><a href=\"http:\/\/www.365mini.com\/page\/jquery_parsejson.htm\">http:\/\/www.365mini.com\/page\/jquery_parsejson.htm<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u524d\u7aef\u65b0\u624b\u5b66\u4e60\u3001\u6574\u7406\u4e00\u4e9b\u7b80\u5355\u7684JavaScript\u77e5\u8bc6\uff0c\u65b9\u4fbf\u4ee5\u540e\u53c2\u8003\u3002 \u6b63\u6587\uff1a \u53c2\u8003\u89e3\u7b54 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,12],"tags":[653,62,181],"class_list":["post-2861","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-tools","tag-ajax","tag-javascript","tag-json"],"views":3650,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2861"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2861\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}