{"id":5338,"date":"2023-01-05T12:28:46","date_gmt":"2023-01-05T04:28:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5338"},"modified":"2023-01-05T12:28:46","modified_gmt":"2023-01-05T04:28:46","slug":"%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87json%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89%e6%8f%9b%e7%82%bamap%e5%b0%8d%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87json%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89%e6%8f%9b%e7%82%bamap%e5%b0%8d%e8%b1%a1\/","title":{"rendered":"\u4f7f\u7528TypeScriptMap\u5c07JSON\u5b57\u7b26\u4e32\u8f49\u63db\u70baMap\u5c0d\u8c61"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, JSON, fromJSON\"><\/p>\n<h1>TypeScript Map \u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u4e3a Map \u5bf9\u8c61(fromJSON())<\/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\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u5065\u58ef\u7684\u4ee3\u78bc\u3002\u5176\u4e2d\u4e00\u500b\u91cd\u8981\u7684\u7279\u6027\u5c31\u662f Map\uff0c\u5b83\u53ef\u4ee5\u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\uff0c\u4ee5\u4fbf\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c JSON \u6578\u64da\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\u3002<\/p>\n<h2>\u4f7f\u7528 TypeScript Map \u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61<\/h2>\n<p>TypeScript Map \u63d0\u4f9b\u4e86\u4e00\u500b <span style=\"font-weight: bold;\">fromJSON()<\/span> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\u3002\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet jsonString = '{\"name\": \"John\", \"age\": 30}';\nlet map = new Map();\nmap.fromJSON(jsonString);\n\nconsole.log(map.get(\"name\")); \/\/ John\nconsole.log(map.get(\"age\")); \/\/ 30\n<\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u9996\u5148\u5b9a\u7fa9\u4e86\u4e00\u500b JSON \u5b57\u7b26\u4e32\uff0c\u7136\u5f8c\u5275\u5efa\u4e86\u4e00\u500b Map \u5c0d\u8c61\uff0c\u6700\u5f8c\u8abf\u7528 fromJSON() \u65b9\u6cd5\u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\uff0c\u6700\u5f8c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 get() \u65b9\u6cd5\u7372\u53d6\u5c0d\u61c9\u7684\u503c\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript Map \u63d0\u4f9b\u4e86\u4e00\u500b fromJSON() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\uff0c\u4ee5\u4fbf\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c JSON \u6578\u64da\u3002\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07 JSON \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 Map \u5c0d\u8c61\uff0c\u5e0c\u671b\u5c0d\u5927\u5bb6\u6709\u6240\u5e6b\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5c07JSON\u5b57\u7b26\u4e32\u8f49\u63db\u70baMap\u5c0d\u8c61\uff0c\u4e26\u63d0\u4f9b\u4e00\u500bfromJSON()\u51fd\u6578\u4f86\u5b8c\u6210\u8f49\u63db\u7684\u904e\u7a0b\u3002\u8b80\u8005\u53ef\u4ee5\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5c07JSON\u5b57\u7b26\u4e32\u8f49\u63db\u70baMap\u5c0d\u8c61\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528fromJSON()\u51fd\u6578\u4f86\u5b8c\u6210\u8f49\u63db\u7684\u904e\u7a0b\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-5338","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-1o6","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5338","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=5338"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5338\/revisions"}],"predecessor-version":[{"id":5339,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5338\/revisions\/5339"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}