{"rsdb":{"rid":"353454","subhead":"","postdate":"0","aid":"250746","fid":"78","uid":"1","topic":"1","content":"
\n

\u9996\u5148 \u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2ajson \u5b57\u4e32<\/p> \n

\n
{\r\n    <\/span>"<\/span>resp<\/span>"<\/span>: {\r\n        <\/span>"<\/span>respCode<\/span>"<\/span>: "<\/span>000000<\/span>"<\/span>,\r\n        <\/span>"<\/span>respMsg<\/span>"<\/span>: "<\/span>\u6210\u529f<\/span>"<\/span>,\r\n        <\/span>"<\/span>app<\/span>"<\/span>: {\r\n            <\/span>"<\/span>appId<\/span>"<\/span>: "<\/span>xxxxxx<\/span>"<\/span>\r\n        }\r\n    }\r\n}<\/span><\/pre> \n <\/div> \n 

go \u5185\u7f6e\u4e86json\u5b57\u4e32\u7684\u89e3\u6790\u5305 "encoding\/json"<\/p> \n

\u63a5\u4e0b\u6765 \u5c31\u9700\u8981\u5bf9\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u4e86\u3002<\/p> \n

\u6309\u7167json\u5e93\u7684\u5206\u6790\uff0c\u5176\u5b9e\u6bcf\u4e00\u4e2a\u82b1\u62ec\u53f7<\/strong>\u5c31\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53<\/p> \n

\u90a3\u4e48\u62c6\u89e3\u7684\u7ed3\u6784\u4f53\u5982\u4e0b\uff1a<\/p> \n

\n
\/\/<\/span>\u4ee3\u8868\u6700\u91cc\u5c42\u7684\u7ed3\u6784\u4f53<\/span>\r\ntype appInfo struct<\/span> {\r\n    Appid <\/span>string<\/span> `json:"<\/span>appId<\/span>"<\/span>`\r\n}\r\n\r\n<\/span>\/\/<\/span>\u4ee3\u8868\u7b2c\u4e8c\u5c42\u7684\u7ed3\u6784\u4f53<\/span>\r\ntype response struct<\/span> {\r\n    RespCode <\/span>string<\/span>  `json:"<\/span>respCode<\/span>"<\/span>`\r\n    RespMsg  <\/span>string<\/span>  `json:"<\/span>respMsg<\/span>"<\/span>`\r\n    AppInfo  appInfo `json:<\/span>"<\/span>app<\/span>"<\/span>`\r\n}\r\n\r\ntype JsonResult <\/span>struct<\/span> {\r\n    Resp response `json:<\/span>"<\/span>resp<\/span>"<\/span>`   \/\/<\/span>\u4ee3\u8868\u6700\u5916\u5c42\u82b1\u62ec\u53f7\u7684\u7ed3\u6784\u4f53 <\/span>\r\n}<\/pre> \n <\/div> \n 

 <\/p> \n

\u7ed3\u6784\u4f53\u7684\u547d\u540d\u5fc5\u987b\u9075\u5faa\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u5927\u5199<\/strong>\uff0c\u5426\u5219json\u5e93\u4f1a\u5ffd\u7565\u6389\u8be5\u6210\u5458\uff0c<\/p> \n

\u800c\u540e\u9762\u7684json:\u201cxxx<\/strong>\u201d xxx<\/strong>\u5219\u9700\u8981\u548cjson\u5b57\u4e32\u91cc\u7684\u540d\u5b57\u76f8\u7b26\u5408\uff1a \u5982\u6700\u5916\u5c42\u7684 json:"**resp**"<\/code> \u548cjson\u5b57\u7b26\u4e32\u91cc\u7684\uff5b\u201cresp<\/strong>\u201d\u4e00\u81f4<\/p> \n

\u7136\u540e\u5b9e\u9645\u7684\u4ee3\u7801\u89e3\u6790\u5982\u4e0b<\/p> \n

\n
package main\r\nimport (\r\n    <\/span>"<\/span>fmt<\/span>"<\/span>\r\n        "<\/span>encoding\/json<\/span>"<\/span>\r\n)\r\ntype appInfo <\/span>struct<\/span> {\r\n    Appid <\/span>string<\/span> `json:"<\/span>appId<\/span>"<\/span>`\r\n}\r\ntype response <\/span>struct<\/span> {\r\n    RespCode <\/span>string<\/span>  `json:"<\/span>respCode<\/span>"<\/span>`\r\n    RespMsg  <\/span>string<\/span>  `json:"<\/span>respMsg<\/span>"<\/span>`\r\n    AppInfo  appInfo `json:<\/span>"<\/span>app<\/span>"<\/span>`\r\n}\r\ntype JsonResult <\/span>struct<\/span> {\r\n    Resp response `json:<\/span>"<\/span>resp<\/span>"<\/span>`\r\n}\r\nfunc main() {\r\n    jsonstr :<\/span>= `{"<\/span>resp<\/span>"<\/span>: {"<\/span>respCode<\/span>"<\/span>: "<\/span>000000<\/span>"<\/span>,"<\/span>respMsg<\/span>"<\/span>: "<\/span>\u6210\u529f<\/span>"<\/span>,"<\/span>app<\/span>"<\/span>: {"<\/span>appId<\/span>"<\/span>: "<\/span>xxxxxx<\/span>"<\/span>}}}`\r\n    <\/span>var<\/span> JsonRes JsonResult \r\n        json.Unmarshal(body, <\/span>&JsonRes)\r\n        fmt.Println(<\/span>"<\/span>after parse<\/span>"<\/span>, JsonRes)\r\n}<\/span><\/pre> \n <\/div> \n 

 <\/p> \n<\/div>","orderid":"0","title":"golang \u5904\u7406 json \u7ed3\u6784\u4f53","smalltitle":"","mid":"0","fname":"GO","special_id":"0","bak_id":"0","info":"0","hits":"73","pages":"1","comments":"0","posttime":"2019-09-17 14:37:02","list":"1568702222","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"golang<\/A> \u5904\u7406<\/A> json<\/A> \u7ed3\u6784<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.35","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"golang \u5904\u7406 json \u7ed3\u6784\u4f53","lastview":"1711877953","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}