"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[5434],{7039:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>t,default:()=>j,frontMatter:()=>l,metadata:()=>c,toc:()=>a});var r=s(5893),i=s(1151),o=s(510);const l={id:"json-serialization",title:"23. JSON \u5e8f\u5217\u5316",sidebar_label:"23. JSON \u5e8f\u5217\u5316"},t=void 0,c={id:"json-serialization",title:"23. JSON \u5e8f\u5217\u5316",description:"\ud83d\udcdd \u6a21\u5757\u66f4\u65b0\u65e5\u5fd7",source:"@site/docs/json-serialization.mdx",sourceDirName:".",slug:"/json-serialization",permalink:"/docs/json-serialization",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/json-serialization.mdx",tags:[],version:"current",lastUpdatedBy:"\u767e\u5c0f\u50e7",lastUpdatedAt:1700452034,formattedLastUpdatedAt:"Nov 20, 2023",frontMatter:{id:"json-serialization",title:"23. JSON \u5e8f\u5217\u5316",sidebar_label:"23. JSON \u5e8f\u5217\u5316"},sidebar:"docs",previous:{title:"22. \u4e8b\u4ef6\u603b\u7ebf (EventBus)",permalink:"/docs/event-bus"},next:{title:"24. \u5373\u65f6\u901a\u8baf",permalink:"/docs/signalr"}},d={},a=[{value:"23.1 \u4ec0\u4e48\u662f JSON
",id:"231-\u4ec0\u4e48\u662f-json",level:2},{value:"23.2 \u5173\u4e8e\u5e8f\u5217\u5316\u5e93",id:"232-\u5173\u4e8e\u5e8f\u5217\u5316\u5e93",level:2},{value:"23.3 IJsonSerializerProvider
\u63a5\u53e3",id:"233-ijsonserializerprovider-\u63a5\u53e3",level:2},{value:"23.4 \u5982\u4f55\u4f7f\u7528",id:"234-\u5982\u4f55\u4f7f\u7528",level:2},{value:"23.4.1 \u83b7\u53d6\u5e8f\u5217\u5316\u5bf9\u8c61",id:"2341-\u83b7\u53d6\u5e8f\u5217\u5316\u5bf9\u8c61",level:3},{value:"23.4.2 \u5e8f\u5217\u5316\u5bf9\u8c61",id:"2342-\u5e8f\u5217\u5316\u5bf9\u8c61",level:3},{value:"23.4.3 \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32",id:"2343-\u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32",level:3},{value:"23.4.4 \u5e8f\u5217\u5316\u66f4\u591a\u914d\u7f6e",id:"2344-\u5e8f\u5217\u5316\u66f4\u591a\u914d\u7f6e",level:3},{value:"23.5 \u9ad8\u7ea7\u7528\u6cd5",id:"235-\u9ad8\u7ea7\u7528\u6cd5",level:2},{value:"23.5.1 \u81ea\u5b9a\u4e49\u5e8f\u5217\u5316\u63d0\u4f9b\u5668",id:"2351-\u81ea\u5b9a\u4e49\u5e8f\u5217\u5316\u63d0\u4f9b\u5668",level:3},{value:"23.5.2 \u5e8f\u5217\u5316\u5c5e\u6027\u540d\u5927\u5199\uff08\u5c5e\u6027\u539f\u6837\u8f93\u51fa\uff09",id:"2352-\u5e8f\u5217\u5316\u5c5e\u6027\u540d\u5927\u5199\u5c5e\u6027\u539f\u6837\u8f93\u51fa",level:3},{value:"23.5.3 \u65f6\u95f4\u683c\u5f0f\u5316\uff08\u65f6\u95f4\u6233\u8f6c\u65f6\u95f4\uff09",id:"2353-\u65f6\u95f4\u683c\u5f0f\u5316\u65f6\u95f4\u6233\u8f6c\u65f6\u95f4",level:3},{value:"23.5.4 \u5ffd\u7565\u5faa\u73af\u5f15\u7528",id:"2354-\u5ffd\u7565\u5faa\u73af\u5f15\u7528",level:3},{value:"23.5.5 \u5305\u542b\u6210\u5458\u5b57\u6bb5\u5e8f\u5217\u5316",id:"2355-\u5305\u542b\u6210\u5458\u5b57\u6bb5\u5e8f\u5217\u5316",level:3},{value:"23.5.6 \u5141\u8bb8\u5c3e\u968f\u9017\u53f7",id:"2356-\u5141\u8bb8\u5c3e\u968f\u9017\u53f7",level:3},{value:"23.5.7 \u5141\u8bb8\u6ce8\u91ca",id:"2357-\u5141\u8bb8\u6ce8\u91ca",level:3},{value:"23.5.8 \u5904\u7406\uff08\u4e2d\u6587\uff09\u4e71\u7801\u95ee\u9898",id:"2358-\u5904\u7406\u4e2d\u6587\u4e71\u7801\u95ee\u9898",level:3},{value:"23.5.9 \u4e0d\u533a\u5206\u5927\u5c0f\u5199",id:"2359-\u4e0d\u533a\u5206\u5927\u5c0f\u5199",level:3},{value:"23.5.10 \u5ffd\u7565\u7279\u5b9a\u5c5e\u6027\u5e8f\u5217\u5316",id:"23510-\u5ffd\u7565\u7279\u5b9a\u5c5e\u6027\u5e8f\u5217\u5316",level:3},{value:"23.5.11 \u52a8\u6001\u5bf9\u8c61\u5c5e\u6027\u540d\u5927\u5199\u95ee\u9898",id:"23511-\u52a8\u6001\u5bf9\u8c61\u5c5e\u6027\u540d\u5927\u5199\u95ee\u9898",level:3},{value:"23.5.12 \u5ffd\u7565\u6240\u6709 null
\u5c5e\u6027",id:"23512-\u5ffd\u7565\u6240\u6709-null-\u5c5e\u6027",level:3},{value:"23.5.13 \u5ffd\u7565\u6240\u6709\u9ed8\u8ba4\u503c\u5c5e\u6027",id:"23513-\u5ffd\u7565\u6240\u6709\u9ed8\u8ba4\u503c\u5c5e\u6027",level:3},{value:"23.5.14 \u63a7\u5236\u5c5e\u6027\u5e8f\u5217\u5316\u987a\u5e8f",id:"23514-\u63a7\u5236\u5c5e\u6027\u5e8f\u5217\u5316\u987a\u5e8f",level:3},{value:"23.5.15 \u91cd\u547d\u540d\u5e8f\u5217\u5316\u540d\u79f0\uff08\u5c5e\u6027\u540d\u79f0\uff09",id:"23515-\u91cd\u547d\u540d\u5e8f\u5217\u5316\u540d\u79f0\u5c5e\u6027\u540d\u79f0",level:3},{value:"23.5.16 JSON
\u5b57\u7b26\u4e32\u7f29\u8fdb",id:"23516-json-\u5b57\u7b26\u4e32\u7f29\u8fdb",level:3},{value:"23.5.17 long
\u7c7b\u578b\u5e8f\u5217\u5316\u65f6\u8f6c string
",id:"23517-long-\u7c7b\u578b\u5e8f\u5217\u5316\u65f6\u8f6c-string",level:3},{value:"23.5.18 DateOnly
\u548c TimeOnly
\u7c7b\u578b\u5e8f\u5217\u5316\u652f\u6301",id:"23518-dateonly-\u548c-timeonly-\u7c7b\u578b\u5e8f\u5217\u5316\u652f\u6301",level:3},{value:"23.5.19 \u7c98\u571f\u5bf9\u8c61 Clay
\u7c7b\u578b\u5e8f\u5217\u5316\u652f\u6301",id:"23519-\u7c98\u571f\u5bf9\u8c61-clay-\u7c7b\u578b\u5e8f\u5217\u5316\u652f\u6301",level:3},{value:"23.5.20 DateTimeOffset
\u53cd\u5e8f\u5217\u5316\u5f02\u5e38",id:"23520-datetimeoffset-\u53cd\u5e8f\u5217\u5316\u5f02\u5e38",level:3},{value:"23.5.21 \u7ee7\u627f/\u6d3e\u751f\u7c7b\u5e8f\u5217\u5316\u95ee\u9898",id:"23521-\u7ee7\u627f\u6d3e\u751f\u7c7b\u5e8f\u5217\u5316\u95ee\u9898",level:3},{value:"23.5.22 \u679a\u4e3e\u548c\u5b57\u7b26\u4e32\u4e92\u8f6c\u95ee\u9898",id:"23522-\u679a\u4e3e\u548c\u5b57\u7b26\u4e32\u4e92\u8f6c\u95ee\u9898",level:3},{value:"23.6 DataTable
\u3001DataSet
\u3001Tuple
\u3001JArray
\uff0cJObject
\uff0cJToken
\u7b49\u5e8f\u5217\u5316\u95ee\u9898",id:"236-datatabledatasettuple-jarrayjobjectjtoken-\u7b49\u5e8f\u5217\u5316\u95ee\u9898",level:2},{value:"23.7 System.Text.Json
\u548c Newtonsoft.Json
\u5b8c\u6574\u5dee\u5f02\u5316\u5bf9\u6bd4",id:"237-systemtextjson-\u548c-newtonsoftjson-\u5b8c\u6574\u5dee\u5f02\u5316\u5bf9\u6bd4",level:2},{value:"23.8 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"238-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function h(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",li:"li",mdxAdmonitionTitle:"mdxAdmonitionTitle",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.a)(),...e.components},{Details:s}=n;return s||function(e,n){throw new Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s,{children:[(0,r.jsx)("summary",{children:"\ud83d\udcdd \u6a21\u5757\u66f4\u65b0\u65e5\u5fd7"}),(0,r.jsx)("div",{children:(0,r.jsxs)("div",{children:[(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"\u65b0\u7279\u6027"})}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["\xa0",(0,r.jsx)(o.Z,{children:"\u65b0\u589e"})," \u65f6\u95f4\u6233\u6a21\u578b\u7ed1\u5b9a\u5668\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a ",(0,r.jsx)(n.code,{children:"DateTime/DateTimeOffset"})," \u7c7b\u578b ",(0,r.jsx)("sup",{children:"4.9.1.5"})," ",(0,r.jsx)("sup",{children:"\u23f1\ufe0f2023.11.20"})," ",(0,r.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/df3053cf081d5e4d8eb63d567ed95c45267e0969",children:"df3053c"})]}),"\n",(0,r.jsxs)(n.li,{children:["\xa0",(0,r.jsx)(o.Z,{children:"\u65b0\u589e"})," ",(0,r.jsx)(n.code,{children:"Newtonsoft.Json"})," \u81ea\u52a8\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a ",(0,r.jsx)(n.code,{children:"DateTime/DateTimeOffset"})," \u7c7b\u578b ",(0,r.jsx)("sup",{children:"4.9.1.3"})," ",(0,r.jsx)("sup",{children:"\u23f1\ufe0f2023.11.17"})," ",(0,r.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/78a589d99eb5985b576e4c96acd6e4890391d6ff",children:"78a589d"})]}),"\n",(0,r.jsxs)(n.li,{children:["\xa0",(0,r.jsx)(o.Z,{children:"\u65b0\u589e"})," ",(0,r.jsx)(n.code,{children:"System.Text.Json"})," \u81ea\u52a8\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a ",(0,r.jsx)(n.code,{children:"DateTime/DateTimeOffset"})," \u7c7b\u578b ",(0,r.jsx)("sup",{children:"4.9.1.2"})," ",(0,r.jsx)("sup",{children:"\u23f1\ufe0f2023.11.17"})," ",(0,r.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/commit/abd5196f5c5160a5df96dad80c7c5aa51b96d5b9",children:"abd5196"})]}),"\n",(0,r.jsxs)(n.li,{children:["\xa0",(0,r.jsx)(o.Z,{children:"\u65b0\u589e"})," ",(0,r.jsx)(n.code,{children:"System.Text.Json"})," \u548c ",(0,r.jsx)(n.code,{children:"Newtonsoft.Json"})," \u5bf9\u7c98\u571f\u5bf9\u8c61 ",(0,r.jsx)(n.code,{children:"Clay"})," \u652f\u6301 ",(0,r.jsx)("sup",{children:"4.8.8.1"})," ",(0,r.jsx)("sup",{children:"\u23f1\ufe0f2023.04.18"})," ",(0,r.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/issues/I6WKRZ",children:"#I6WKRZ"})]}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(n.li,{children:["\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"\u7a81\u7834\u6027\u53d8\u5316"})}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["\xa0",(0,r.jsx)(o.Z,{children:"\u8c03\u6574"})," ",(0,r.jsxs)(n.strong,{children:[(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u5e8f\u5217\u5316\u63a5\u53e3\uff0c\u6dfb\u52a0 ",(0,r.jsx)(n.code,{children:"Deserialize"})," \u53cd\u5e8f\u5217\u5316\u65b9\u6cd5"]})," ",(0,r.jsx)("sup",{children:"4.8.8.15"})," ",(0,r.jsx)("sup",{children:"\u23f1\ufe0f2023.05.15"})," ",(0,r.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/pulls/815",children:"!815"})," \u611f\u8c22 ",(0,r.jsx)(n.a,{href:"https://gitee.com/YaChengMu",children:"@YaChengMu"})]}),"\n"]}),"\n"]}),"\n"]}),(0,r.jsxs)(s,{style:{marginLeft:50},children:[(0,r.jsx)("summary",{children:"\u67e5\u770b\u53d8\u5316"}),(0,r.jsxs)("div",{children:[(0,r.jsxs)(n.p,{children:["\u6dfb\u52a0 ",(0,r.jsx)(n.code,{children:"25-32\u884c"})," \u63a5\u53e3\u65b9\u6cd5\uff1a"]}),(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {25-32}",children:'namespace Furion.JsonSerialization;\r\n\r\n/// \r\n/// Json \u5e8f\u5217\u5316\u63d0\u4f9b\u5668\r\n/// \r\npublic interface IJsonSerializerProvider\r\n{\r\n /// \r\n /// \u5e8f\u5217\u5316\u5bf9\u8c61\r\n /// \r\n /// \r\n /// \r\n /// \r\n string Serialize(object value, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\r\n /// \r\n /// \r\n /// \r\n /// \r\n /// \r\n T Deserialize(string json, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\r\n /// \r\n /// \r\n /// \r\n /// \r\n /// \r\n object Deserialize(string json, Type returnType, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u8fd4\u56de\u8bfb\u53d6\u5168\u5c40\u914d\u7f6e\u7684 JSON \u9009\u9879\r\n /// \r\n /// \r\n object GetSerializerOptions();\r\n}\n'})}),(0,r.jsxs)(n.p,{children:["\u5982\u679c\u4f7f\u7528 ",(0,r.jsx)(n.code,{children:"Newtonsoft.Json"})," \u5219\u53ea\u9700\u6dfb\u52a0\u4ee5\u4e0b\u5b9e\u73b0\u5373\u53ef\uff1a"]}),(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {8-11}",children:'/// \r\n/// \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\r\n/// \r\n/// \r\n/// \r\n/// \r\n/// \r\npublic object Deserialize(string json, Type returnType, object jsonSerializerOptions = null)\r\n{\r\n return JsonConvert.DeserializeObject(json, returnType, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);\r\n}\n'})})]})]})]})})]}),"\n",(0,r.jsx)(n.admonition,{title:"\u7248\u672c\u8bf4\u660e",type:"important",children:(0,r.jsxs)(n.p,{children:["\u4ee5\u4e0b\u5185\u5bb9\u4ec5\u9650 ",(0,r.jsx)(n.code,{children:"Furion 1.16.0 +"})," \u7248\u672c\u4f7f\u7528\u3002"]})}),"\n",(0,r.jsxs)(n.h2,{id:"231-\u4ec0\u4e48\u662f-json",children:["23.1 \u4ec0\u4e48\u662f ",(0,r.jsx)(n.code,{children:"JSON"})]}),"\n",(0,r.jsxs)(n.blockquote,{children:["\n",(0,r.jsx)(n.p,{children:"JSON (JavaScript Object Notation, JS \u5bf9\u8c61\u6807\u8bb0) \u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\u3002\u5b83\u57fa\u4e8e ECMAScript (w3c \u5236\u5b9a\u7684 js \u89c4\u8303)\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u91c7\u7528\u5b8c\u5168\u72ec\u7acb\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u6587\u672c\u683c\u5f0f\u6765\u5b58\u50a8\u548c\u8868\u793a\u6570\u636e\u3002\u7b80\u6d01\u548c\u6e05\u6670\u7684\u5c42\u6b21\u7ed3\u6784\u4f7f\u5f97 JSON \u6210\u4e3a\u7406\u60f3\u7684\u6570\u636e\u4ea4\u6362\u8bed\u8a00\u3002 \u6613\u4e8e\u4eba\u9605\u8bfb\u548c\u7f16\u5199\uff0c\u540c\u65f6\u4e5f\u6613\u4e8e\u673a\u5668\u89e3\u6790\u548c\u751f\u6210\uff0c\u5e76\u6709\u6548\u5730\u63d0\u5347\u7f51\u7edc\u4f20\u8f93\u6548\u7387\u3002"}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"\u7b80\u5355\u6765\u8bf4\uff0cJSON\uff0c\u662f\u4e00\u79cd\u6570\u636e\u683c\u5f0f\uff0c\u5728\u4e0e\u540e\u7aef\u7684\u6570\u636e\u4ea4\u4e92\u4e2d\u6709\u8f83\u4e3a\u5e7f\u6cdb\u7684\u5e94\u7528\u3002"}),"\n",(0,r.jsx)(n.h2,{id:"232-\u5173\u4e8e\u5e8f\u5217\u5316\u5e93",children:"23.2 \u5173\u4e8e\u5e8f\u5217\u5316\u5e93"}),"\n",(0,r.jsxs)(n.p,{children:["\u76ee\u524d\u5728 C# \u8bed\u8a00\u4e2d\u6709\u4e24\u4e2a\u4e3b\u6d41\u7684 ",(0,r.jsx)(n.code,{children:"JSON"})," \u5e8f\u5217\u5316\u64cd\u4f5c\u5e93\uff1a"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"System.Text.Json"}),"\uff1a",(0,r.jsx)(n.code,{children:".NET Core"})," \u5185\u7f6e ",(0,r.jsx)(n.code,{children:"JSON"})," \u5e8f\u5217\u5316\u5e93\uff0c\u4e5f\u662f ",(0,r.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u9ed8\u8ba4\u5b9e\u73b0"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"Newtonsoft.Json"}),"\uff1a\u76ee\u524d\u4f7f\u7528\u4eba\u6570\u6700\u591a\u7684 ",(0,r.jsx)(n.code,{children:"JSON"})," \u5e8f\u5217\u5316\u5e93\uff0c\u9700\u8981\u5b89\u88c5 ",(0,r.jsx)(n.code,{children:"Microsoft.AspNetCore.Mvc.NewtonsoftJson"})," \u62d3\u5c55\u5305"]}),"\n"]}),"\n",(0,r.jsxs)(n.p,{children:["\u7531\u4e8e\u76ee\u524d ",(0,r.jsx)(n.code,{children:"System.Text.Json"})," \u76f8\u6bd4 ",(0,r.jsx)(n.code,{children:"Newtonsoft.Json"})," \u529f\u80fd\u548c\u7a33\u5b9a\u6027\u6709\u8bb8\u591a\u4e0d\u8db3\u4e4b\u5904\uff0c\u6bd4\u5982\u5faa\u73af\u5f15\u7528\u95ee\u9898\u5728 ",(0,r.jsx)(n.code,{children:"System.Text.Json"})," \u65e0\u89e3\u3002\u4f46\u5728 ",(0,r.jsx)(n.code,{children:".NET 6"})," \u4e4b\u540e\u5f97\u5230\u89e3\u51b3\u3002"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u4e3a\u4e86\u89e3\u51b3\u591a\u79cd\u5e8f\u5217\u5316\u5de5\u5177\u914d\u7f6e\u548c\u7528\u6cd5\u4e0a\u7684\u5dee\u5f02\u95ee\u9898\uff0c\u62bd\u8c61\u51fa\u4e86 ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u63a5\u53e3\u3002"]}),"\n",(0,r.jsxs)(n.h2,{id:"233-ijsonserializerprovider-\u63a5\u53e3",children:["23.3 ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u63a5\u53e3"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86 ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u63a5\u53e3\u89c4\u8303\uff0c\u540c\u65f6",(0,r.jsx)(n.strong,{children:"\u8981\u6c42\u5b9e\u73b0\u8be5\u63a5\u53e3\u7684\u5b9e\u4f53\u90fd\u5fc5\u987b\u91c7\u7528\u5355\u4f8b\u6a21\u5f0f"}),"\uff0c\u8be5\u63a5\u53e3\u5b9a\u4e49\u4ee3\u7801\u5982\u4e0b\uff1a"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'namespace Furion.JsonSerialization;\r\n\r\n/// \r\n/// Json \u5e8f\u5217\u5316\u63d0\u4f9b\u5668\r\n/// \r\npublic interface IJsonSerializerProvider\r\n{\r\n /// \r\n /// \u5e8f\u5217\u5316\u5bf9\u8c61\r\n /// \r\n /// \r\n /// \r\n /// \r\n string Serialize(object value, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\r\n /// \r\n /// \r\n /// \r\n /// \r\n /// \r\n T Deserialize(string json, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32\r\n /// \r\n /// \r\n /// \r\n /// \r\n /// \r\n object Deserialize(string json, Type returnType, object jsonSerializerOptions = default);\r\n\r\n /// \r\n /// \u8fd4\u56de\u8bfb\u53d6\u5168\u5c40\u914d\u7f6e\u7684 JSON \u9009\u9879\r\n /// \r\n /// \r\n object GetSerializerOptions();\r\n}\n'})}),"\n",(0,r.jsx)(n.admonition,{title:"\u9ed8\u8ba4\u5b9e\u73b0",type:"important",children:(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"SystemTextJsonSerializerProvider"})," \u7c7b\u662f ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u63a5\u53e3\u7684\u9ed8\u8ba4\u5b9e\u73b0\uff0c\u5728\u5e94\u7528\u542f\u52a8\u65f6\u5df2\u9ed8\u8ba4\u6ce8\u518c\u3002"]})}),"\n",(0,r.jsx)(n.h2,{id:"234-\u5982\u4f55\u4f7f\u7528",children:"23.4 \u5982\u4f55\u4f7f\u7528"}),"\n",(0,r.jsx)(n.h3,{id:"2341-\u83b7\u53d6\u5e8f\u5217\u5316\u5bf9\u8c61",children:"23.4.1 \u83b7\u53d6\u5e8f\u5217\u5316\u5bf9\u8c61"}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.code,{children:"Furion"})," \u6846\u67b6\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u83b7\u53d6 ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})," \u5b9e\u4f8b\uff1a"]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["\u6784\u9020\u51fd\u6570\u6ce8\u5165 ",(0,r.jsx)(n.code,{children:"IJsonSerializerProvider"})]}),"\n",(0,r.jsxs)(n.li,{children:["\u9759\u6001\u7c7b ",(0,r.jsx)(n.code,{children:"JSON.GetJsonSerializer()"})," \u65b9\u5f0f\uff0c",(0,r.jsxs)(n.strong,{children:["\u67e5\u770b ",(0,r.jsx)(n.a,{href:"/docs/global/json",children:"JSON \u9759\u6001\u7c7b"})]})]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"\u5982\uff1a"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {10,13}",children:"using Furion.DynamicApiController;\r\nusing Furion.JsonSerialization;\r\n\r\nnamespace Furion.Application\r\n{\r\n public class JsonDemo : IDynamicApiController\r\n {\r\n private readonly IJsonSerializerProvider _jsonSerializer;\r\n private readonly IJsonSerializerProvider _jsonSerializer2;\r\n public JsonDemo(IJsonSerializerProvider jsonSerializer)\r\n {\r\n _jsonSerializer = jsonSerializer;\r\n _jsonSerializer2 = JSON.GetJsonSerializer();\r\n }\r\n }\r\n}\n"})}),"\n",(0,r.jsx)(n.h3,{id:"2342-\u5e8f\u5217\u5316\u5bf9\u8c61",children:"23.4.2 \u5e8f\u5217\u5316\u5bf9\u8c61"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'public string GetText()\r\n{\r\n return _jsonSerializer.Serialize(new\r\n {\r\n Id = 1,\r\n Name = "Furion"\r\n });\r\n}\n'})}),"\n",(0,r.jsx)(n.h3,{id:"2343-\u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32",children:"23.4.3 \u53cd\u5e8f\u5217\u5316\u5b57\u7b26\u4e32"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:'public object GetObject()\r\n{\r\n var json = "{\\"Id\\":1,\\"Name\\":\\"Furion\\"}";\r\n var obj = _jsonSerializer.Deserialize