{"id":28152,"date":"2024-11-24T12:06:15","date_gmt":"2024-11-24T04:06:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28152\/"},"modified":"2024-11-24T12:06:15","modified_gmt":"2024-11-24T04:06:15","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87-javascript-%e4%bb%a3%e7%a0%81%e5%ae%9e%e7%8e%b0%e5%b0%86-json-%e5%af%b9%e8%b1%a1%e4%b8%ad%e7%89%b9%e5%ae%9a%e9%94%ae%e5%80%bc%e6%9b%bf%e6%8d%a2%e4%b8%ba%e6%8c%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28152\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7 JavaScript \u4ee3\u7801\u5b9e\u73b0\u5c06 JSON \u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173141029871245.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7 JavaScript \u4ee3\u7801\u5b9e\u73b0\u5c06 JSON \u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7 JavaScript \u4ee3\u7801\u5b9e\u73b0\u5c06 JSON \u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5c06\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\u7684\u6280\u5de7<\/strong><\/p>\n<p>\u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u5c06\u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u7684\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u901a\u8fc7 JavaScript \u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>\u5047\u8bbe\u6709\u8fd9\u6837\u7684 JSON \u5bf9\u8c61\uff1a<\/p>\n<pre>{\n    \"assessingOfficer\": [\n        {\n            \"AssessingOfficerName\": \"\u5361\u7279\u7433\u5a1c\",\n            \"AssessingStatus\": 1,\n            \"AssessingOfficerType\": 1,\n            \"dataTime\": \"2024-04-09 17:12:04\",\n            \"remarks\": \"\u6211\u4eec\u5728\u4e00\u8d77\",\n            \"UserName\": \"\u5361\u7279\u7433\u5a1c\"\n        },\n        {\n            \"dataTime\": \"2024-04-09 17:07:17\",\n            \"remarks\": \"222222222222\",\n            \"UserName\": \"\u5361\u7279\u7433\u5a1c\",\n            \"AssessingOfficerName\": \"\u5361\u7279\u7433\u5a1c\",\n            \"AssessingStatus\": 2,\n            \"AssessingOfficerType\": 2\n        },\n        {\n            \"dataTime\": \"2024-04-09 17:07:33\",\n            \"remarks\": \"22222222222222\",\n            \"UserName\": \"\u5361\u7279\u7433\u5a1c\",\n            \"AssessingOfficerName\": \"\u5361\u7279\u7433\u5a1c\",\n            \"AssessingStatus\": 2,\n            \"AssessingOfficerType\": 2\n        }\n    ]\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 map() \u548c JSON.parse()<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 map() \u65b9\u6cd5\u83b7\u53d6 AssessingStatus \u7684\u503c\uff0c\u5e76\u4f7f\u7528 JSON.parse() \u65b9\u6cd5\u521b\u5efa\u6df1\u5c42\u526f\u672c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>const assessingOfficer = [\n  {\n    AssessingStatus: 2,\n  },\n  {\n    AssessingStatus: 2,\n  },\n  {\n    AssessingStatus: 1,\n  },\n  {\n    AssessingStatus: 1,\n  },\n  {\n    AssessingStatus: 2,\n  },\n  {\n    AssessingStatus: 2,\n  },\n  {\n    AssessingStatus: 2,\n  },\n];\n\nvar assessingOfficerArr = assessingOfficer.map((el) =&gt; el.AssessingStatus);\n\nvar deepAssessingOfficerArr = JSON.parse(JSON.stringify(assessingOfficerArr));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5faa\u73af\u66ff\u6362\u503c<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u66ff\u6362\u7279\u5b9a\u503c\uff1a<\/p>\n<pre>for (let i = 0; i &lt; deepAssessingOfficerArr.length; i++) {\n  if (i === 0)\n    assessingOfficerArr[0] = deepAssessingOfficerArr[0] === 1 ? 3 : deepAssessingOfficerArr[0];\n  if (i &gt; 0)\n    assessingOfficerArr[i] =\n      deepAssessingOfficerArr[i] === 1\n        ? 3\n        : deepAssessingOfficerArr[i - 1] === 1\n        ? 1\n        : deepAssessingOfficerArr[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u5faa\u73af\u4e2d\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a 1\uff0c\u5c06\u5176\u66ff\u6362\u4e3a 3\uff0c\u5426\u5219\u4fdd\u6301\u4e0d\u53d8\u3002<\/li>\n<li>\u5bf9\u4e8e\u5176\u4ed6\u5143\u7d20\uff0c\u5982\u679c\u5f53\u524d\u5143\u7d20\u4e3a 1\uff0c\u5219\u5c06\u5176\u66ff\u6362\u4e3a 3\u3002<\/li>\n<li>\u5982\u679c\u5f53\u524d\u5143\u7d20\u4e4b\u524d\u7684\u4e00\u4e2a\u5143\u7d20\u4e3a 1\uff0c\u5219\u5c06\u5176\u66ff\u6362\u4e3a 1\u3002<\/li>\n<li>\u5426\u5219\uff0c\u4fdd\u6301\u5f53\u524d\u5143\u7d20\u4e0d\u53d8\u3002<\/li>\n<\/ul>\n<p>\u6700\u540e\u7684 assessingOfficerArr \u5c06\u5305\u542b\u66ff\u6362\u540e\u7684\u503c\uff1a<\/p>\n<pre>[3, 1, 3, 1, 3, 1, 3]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7 JavaScript \u4ee3\u7801\u5b9e\u73b0\u5c06 JSON \u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u7279\u5b9a\u952e\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\u7684\u6280\u5de7 \u5728\u524d\u7aef\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u5c06\u5bf9\u8c61\u4e2d\u7279\u5b9a\u952e\u7684\u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u989c\u8272\u3002\u4ee5\u4e0b\u662f\u901a\u8fc7 JavaScript \u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u65b9\u6cd5\uff1a \u5047\u8bbe\u6709\u8fd9\u6837\u7684 JSON \u5bf9\u8c61\uff1a { &#8220;assessingOfficer&#8221;: [ { &#8220;AssessingOfficerName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221;, &#8220;AssessingStatus&#8221;: 1, &#8220;AssessingOfficerType&#8221;: 1, &#8220;dataTime&#8221;: &#8220;2024-04-09 17:12:04&#8221;, &#8220;remarks&#8221;: &#8220;\u6211\u4eec\u5728\u4e00\u8d77&#8221;, &#8220;UserName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221; }, { &#8220;dataTime&#8221;: &#8220;2024-04-09 17:07:17&#8221;, &#8220;remarks&#8221;: &#8220;222222222222&#8221;, &#8220;UserName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221;, &#8220;AssessingOfficerName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221;, &#8220;AssessingStatus&#8221;: 2, &#8220;AssessingOfficerType&#8221;: 2 }, { &#8220;dataTime&#8221;: &#8220;2024-04-09 17:07:33&#8221;, &#8220;remarks&#8221;: &#8220;22222222222222&#8221;, &#8220;UserName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221;, &#8220;AssessingOfficerName&#8221;: &#8220;\u5361\u7279\u7433\u5a1c&#8221;, &#8220;AssessingStatus&#8221;: 2, &#8220;AssessingOfficerType&#8221;: 2 } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-28152","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28152"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28152\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}