{"id":5332,"date":"2023-01-05T12:27:55","date_gmt":"2023-01-05T04:27:55","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5332"},"modified":"2023-01-05T12:27:55","modified_gmt":"2023-01-05T04:27:55","slug":"%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87map%e5%b0%8d%e8%b1%a1%e8%bd%89%e6%8f%9b%e7%82%bajson%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87map%e5%b0%8d%e8%b1%a1%e8%bd%89%e6%8f%9b%e7%82%bajson%e5%ad%97%e7%ac%a6%e4%b8%b2\/","title":{"rendered":"\u4f7f\u7528TypeScriptMap\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70baJSON\u5b57\u7b26\u4e32"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, JSON, toJSON()\"><\/p>\n<h1>TypeScript Map \u5c07 Map \u5bf9\u8c61\u8f6c\u4e3a JSON \u5b57\u7b26\u4e32(toJSON())<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\u3002\u5b83\u4e5f\u652f\u6301 Map \u5c0d\u8c61\uff0c\u5b83\u662f\u4e00\u7a2e\u9375\u503c\u5c0d\u7684\u6578\u64da\u7d50\u69cb\uff0c\u53ef\u4ee5\u7528\u4f86\u5b58\u5132\u4efb\u610f\u985e\u578b\u7684\u6578\u64da\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07 Map \u5c0d\u8c61\u8f6c\u63db\u70ba JSON \u5b57\u7b26\u4e32\u3002<\/p>\n<h2>\u4f7f\u7528 TypeScript Map \u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32<\/h2>\n<p>TypeScript Map \u63d0\u4f9b\u4e86\u4e00\u500b <strong>toJSON()<\/strong> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32\u3002\u8a72\u65b9\u6cd5\u63a5\u53d7\u4e00\u500b\u53ef\u9078\u7684\u53c3\u6578\uff0c\u7528\u65bc\u6307\u5b9a\u8f38\u51fa\u7684 JSON \u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u4ee3\u78bc\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet map = new Map();\nmap.set('name', 'John');\nmap.set('age', 30);\n\nlet jsonString = map.toJSON();\nconsole.log(jsonString);\n\/\/ {\"name\":\"John\",\"age\":30}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u793a\u4f8b\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b Map \u5c0d\u8c61\uff0c\u4e26\u4f7f\u7528 <strong>toJSON()<\/strong> \u65b9\u6cd5\u5c07\u5176\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32\u3002\u6211\u5011\u4f7f\u7528 <strong>toJSON()<\/strong> \u65b9\u6cd5\u5c07 Map \u5c0d\u8c61\u8f49\u63db\u70ba JSON \u5b57\u7b26\u4e32\uff0c\u4e26\u6307\u5b9a\u8f38\u51fa\u7684 JSON \u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aTypeScriptMap\u662f\u4e00\u7a2e\u5c0d\u8c61\uff0c\u53ef\u4ee5\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70baJSON\u5b57\u7b26\u4e32\uff0c\u4ee5\u4fbf\u5728JavaScript\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70baJSON\u5b57\u7b26\u4e32\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528toJSON()\u65b9\u6cd5\u5c07Map\u5c0d\u8c61\u8f49\u63db\u70baJSON\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5332","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1o0","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5332"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5332\/revisions"}],"predecessor-version":[{"id":5333,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5332\/revisions\/5333"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}