{"id":217,"date":"2021-04-27T19:26:10","date_gmt":"2021-04-27T11:26:10","guid":{"rendered":"https:\/\/hisui.cn\/?p=217"},"modified":"2023-07-28T18:48:54","modified_gmt":"2023-07-28T10:48:54","slug":"cache%e4%b8%ad%e8%bd%acjson%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"http:\/\/hisui.cn\/?p=217","title":{"rendered":"Cache\u4e2d\u8f6cJSON\u5b57\u7b26"},"content":{"rendered":"<h2>Cache\u4e2d\u8f6cJson\u5b57\u7b26<\/h2>\n<p>Cache2016\u53ca\u4ee5\u540e\u7684Cache\u7248\u672c\u4e2dM\u539f\u751f\u652f\u6301Json\u8f6c\u6362\uff0c\u4f46\u57282010\u53ca\u4ee5\u524d\u7684Cache\u7248\u672c\u4e2dM\u4e0d\u539f\u751f\u652f\u6301\u8f6c\u6362\uff0c\u53ea\u80fd\u81ea\u5df1\u7f16\u5199\u65b9\u6cd5\u6765\u8f6c\u5bf9\u8c61\uff0c\u4ee5\u4e0b\u4ecb\u7ecd\u6211\u7ecf\u5e38\u4f7f\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<h3>ext.util.JsonObject\u7c7b<\/h3>\n<p>ext.util.JsonObject\u4e3aJSON\u8f6c\u6362\u7684\u5de5\u5177\u7c7b\uff0c\u53ef\u628a\u5bf9\u8c61\u8f6c\u51faJSON\u5b57\u7b26\u4e32\/\u5b57\u7b26\u6d41\uff0c\u5bf9\u8c61\u8f6c\u6210XML\u6a21\u677f\u6253\u5370\u4e32\uff0c\u628aJSON\u5b57\u7b26\u4e32\u8f6c\u6210\u5bf9\u8c61(\u53ea\u652f\u6301\u4e00\u5c42\u7ed3\u6784)\uff0c\u4e14\u53ef\u5b9a\u70b9\u53d6\u503c\uff0c\u4e5f\u53ef\u5b9a\u70b9\u8d4b\u503c\u3002<\/p>\n<h4>\u5bf9\u8c61\u8f6cJSON\u6d41<\/h4>\n<pre><code class=\"language-csharp line-numbers\">Set Obj = ##Class(User.CTPaymode).%OpenId(2,0)\n\/*\nParam : {Object} Obj \u5fc5\u586b\u3002\nParam : {String} cn \u53ef\u9009\u9879\u3002\u7c7b\u540d\uff0c\u5982\uff1aUser.CTPaymode\nParam : {ext.util.JsonObject} JsonObject\u5bf9\u8c61 \u53ef\u9009\u9879\u3002\u7528\u4e8e\u6307\u5b9a\u8f6c\u6362\u683c\u5f0f\u3002\n\u5982\u679cObj\u627f\u7ee7\u81ea%XML.Adaptor,\u4e14\u67d0\u5c5e\u6027\u7684XMLNAME\u53c2\u6570\u6709\u503c\uff0c\u5219\u4f7f\u7528XMLNAME\u503c\u4f5cKey\uff0c\u5982pat_name\n*\/\n\/\/ \u53d6\u5f97Json\u5b57\u7b26\u6d41\nSet JsonStream = ##class(ext.util.JsonObject).ObjToJsonStream(Obj)\n\/\/ \u53d6\u5f97Json\u5b57\u7b26\u4e32\uff0c\u4f1a\u6709\u622a\u53d6\u98ce\u9669\u3002\uff08\u5148\u83b7\u5f97Json\u6d41\uff0c\u7136\u540e\u8bfb\u53d6\u6700\u5927\u957f\u5ea6\u5b57\u7b26\u4e32\u3002\uff09\nSet JsonStr = ##class(ext.util.JsonObject).ObjToJson(Obj)\nSet Obj = \"\"\n<\/code><\/pre>\n<h4>\u83b7\u5f97JSON\u5b57\u7b26\u4e32\u4e2d\u503c<\/h4>\n<pre><code class=\"language-csharp line-numbers\">Set JsonStr = \"{\"\"name\"\":\"\"neer\"\",\"\"age\"\":12,\"\"company\"\":{\"\"name\"\":\"\"MediWay\"\"},\"\"children\"\":[{\"\"name\"\":\"\"sub1\"\"},{\"\"name\"\":\"\"sub2\"\"}]}\"\nSet JsonObj = ##class(ext.util.JsonObject).FromJSON(JsonStr)\ndo JsonObj.Put(\"sex\",\"\u7537\").Put(\"addr\",\"myaddr\")  \/\/\u4efb\u4f55JsonObj\u90fd\u53ef\u4f7f\u7528Put\u8ffd\u52a0\u503c\nWrite JsonObj.Get(\"sex\") \/\/\u7537\nWrite JsonObj.Get(\"name\") \/\/neer\nWrite JsonObj.Get(\"age\")  \/\/12\nWrite JsonObj.Get(\"company\",\"name\")  \/\/MediWay\nWrite JsonObj.Get(\"children\",0,\"name\") \/\/sub1 \u7d22\u5f15\u4ece0\u5f00\u59cb\nWrite JsonObj.Get(\"children\",1,\"name\") \/\/sub2\n<\/code><\/pre>\n<h4>\u83b7\u5f97XML\u6a21\u677f\u6253\u5370\u5185\u5bb9\u5b57\u7b26\u4e32<\/h4>\n<pre><code class=\"language-csharp line-numbers\">Set JsonObj = ##class(ext.util.JsonObject).%New()\nDo JsonObj.Put(\"RegNo\",\"11124567\").Put(\"PatName\",\"\u5f20\u4e09\").Put(\"SignImg\",\"http:\/\/xx\/xx.png\")\n\/\/\u5f97\u5230\u524d\u53f0XML\u6253\u5370\u7684\u6570\u636e\uff0c\u4e0d\u7528\u7e41\u9501\u62fc\u4e32\nSet XMLPrintData = JsonObj.GetPrintData()  \/\/RegNo$c(2)1112^PatName$(2)\u5f20\u4e09^SignImg$c(2)http:\/\/xx\/xx.png\nSet JsonData = JsonObj.Json()  \/\/ {\"RegNo\":\"11124567\",\"PatName\":\"\u5f20\u4e09\",\"SignImg\":\"http:\/\/xx\/xx.png\"}\n\/\/ \u5f97\u5230\u6392\u5e8f\u540e\u7684\u8bf7\u6c42\u53c2\u6570\nSet ReqData= JsonObj.ToGetParam() \/\/PatName=\u5f20\u4e09&amp;RegNo=11124567&amp;SignImg=http:\/\/xx\/xx.png\n<\/code><\/pre>\n<h4>\u5bf9\u8c61\u8f6cJSON\u6162\u7684\u95ee\u9898<\/h4>\n<p>\u5982\u679c\u4f7f\u7528\u5bf9\u8c61\u8f6cJSON\u5b57\u7b26\u4e32\uff0c\u5bf9\u8c61\u590d\u6742\uff0c\u5c42\u6df1\u4e14\u884c\u591a\u65f6\uff0c\u7cfb\u5217\u5316\u5bf9\u8c61\u975e\u5e38\u8017\u65f6\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528<code>\u591a\u7ef4\u6570\u7ec4\u8f6cJSON\u5b57\u7b26\u4e32<\/code>\u4f18\u5316\u901f\u5ea6\u3002<\/p>\n<pre><code class=\"language-csharp line-numbers\">Set Arr(\"name\") = \"neer\", Arr(\"sex\") = \"\u7537\", Arr(\"age\") = 12\nFor i=0:1:10000{ \/\/\u4ece0\u5f00\u59cb\u65f6\u624d\u4f1a\u8f6c\u6210[{},{}],\u5426\u5219\u662f\u8f6c\u6210{\"1\":{},\"2\":{},...}\n    Set Arr(\"children\",i,\"name\")=\"sub\"_i\n}\nM @\"tmp\" = Arr\nSet RtnObj = ##class(%GlobalCharacterStream).%New()\nDo encode3^json(\"tmp\",.RtnObj)\nk @\"tmp\"\nW rtnObj.Read() \/\/\/{\"age\":12,\"children\":[{\"name\":\"sub0\"},{\"name\":\"sub1\"},{\"name\":\"sub2\"},...],\"name\":\"neer\",\"sex\":\"\u7537\"}\n<\/code><\/pre>\n<h4>\u5bf9\u8c61\u8f6cJSON (Boolean\u578b)<code>20211008<\/code><\/h4>\n<pre><code class=\"language-csharp line-numbers\">    Set Obj = ##class(BSP.SYS.DTO.Base).%New()\n    Set Obj.success=1      \/\/m\u4e2d1\u8868\u793a\u771f\uff0c0\u8868\u793a\u5047\u3002\n    Set jsonObj = ##class(ext.util.JsonObject).%New()\n    Set jsonObj.BooleanFormat = \"true|false\"   \/\/\u8868\u793a\u8f6c\u6210\u4e0d\u5e26\u53cc\u5f15\u53f7\u7684true\u6216false\n    d ##class(ext.util.JsonObject).ObjectToJSONStream(Obj,.Stream,\"\",jsonObj)\n    Set Obj=\"\",jsonObj=\"\"  \n    Q Stream  \/\/ Stream.Read() =&gt; {\"msg\":\"\",\"results\":[],\"success\":true} \n<\/code><\/pre>\n<h4>JSON\u5b57\u7b26\u4e32\u8f6cM\u6570\u7ec4<\/h4>\n<pre><code class=\"language-csharp line-numbers\">ClassMethod tjson() [ ProcedureBlock = 0 ]\n{\n    Set json = \"{\"\"key\"\":\"\"w\\u0022ww\"\",\"\"key1\"\":{\"\"key2\"\":\"\"w\\u005Cww\"\"},\"\"name\"\":\"\"wanghc\"\"}\"\n    if $$decode^json(json,\"PLIST\")=0{\n        w PLIST(\"name\")_\",\"_PLIST(\"key\")_\",\"_PLIST(\"key1\",\"key2\")\n    }\n}\nClassMethod tjson2() [ ProcedureBlock =1 ]\n{\n    Set json = \"{\"\"key\"\":\"\"w\\u0022ww\"\",\"\"key1\"\":{\"\"key2\"\":\"\"w\\u005Cww\"\"},\"\"name\"\":\"\"wanghc\"\"}\"\n    if $$decode^json(json,\"PLIST\")=0{\n        m Arr = @\"PLIST\"\n        w Arr(\"name\")_\",\"_Arr(\"key\")_\",\"_Arr(\"key1\",\"key2\")\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Cache\u4e2d\u8f6cJSON\u5b57\u7b26<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[91,59,61,60],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-imedical_info","category-m_lang","tag-boolean","tag-json"],"_links":{"self":[{"href":"http:\/\/hisui.cn\/index.php?rest_route=\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hisui.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hisui.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hisui.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hisui.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217"}],"version-history":[{"count":0,"href":"http:\/\/hisui.cn\/index.php?rest_route=\/wp\/v2\/posts\/217\/revisions"}],"wp:attachment":[{"href":"http:\/\/hisui.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hisui.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hisui.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}