{"id":343176,"date":"2021-02-15T16:17:17","date_gmt":"2021-02-15T08:17:17","guid":{"rendered":"http:\/\/4563.org\/?p=343176"},"modified":"2021-02-15T16:17:17","modified_gmt":"2021-02-15T08:17:17","slug":"show-v2ex-cmarshal-c-struct-json-%e5%ba%8f%e5%88%97%e5%8c%96-%e5%8f%8d%e5%ba%8f%e5%88%97%e5%8c%96%e4%bb%a3%e7%a0%81%e7%94%9f%e6%88%90%e5%99%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=343176","title":{"rendered":"Show V2EX: cmarshal: C struct JSON \u5e8f\u5217\u5316 \/ \u53cd\u5e8f\u5217\u5316\u4ee3\u7801\u751f\u6210\u5668"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Show V2EX: cmarshal: C struct JSON \u5e8f\u5217\u5316 \/ \u53cd\u5e8f\u5217\u5316\u4ee3\u7801\u751f\u6210\u5668               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gyf304 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u53ea\u9700\u8981\u7ed9\u4f60\u7684 C struct \u52a0\u5982\u4e0b\u7684\u4e00\u884c\u6ce8\u91ca\u5c31\u53ef\u4ee5\u7528 <code>cmarshal<\/code> \u81ea\u52a8\u751f\u6210 JSON \u5e8f\u5217\u5316 \/ \u53cd\u5e8f\u5217\u5316\u4ee3\u7801\u3002<\/p>\n<pre><code>\/* cmarshal:`true` *\/ <\/code><\/pre>\n<p>\u53ef\u4ee5\u4e0d\u8d39\u5439\u7070\u4e4b\u529b\u5b9e\u73b0\u5728 C \u8bed\u8a00\u4e2d\u5b9e\u73b0 JSON \u914d\u7f6e\u6587\u4ef6\u7684\u8bfb\u53d6\u3002<\/p>\n<p>GitHub<\/p>\n<p>\u89c9\u5f97\u6709\u610f\u601d\u7684\u8bdd\u5e2e\u5fd9\u52a0\u4e2a\u661f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5283360\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : justin2018 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f88\u68d2\u7684\u5de5\u5177 \u591a\u8c22\u5206\u4eab                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5283361\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u542c\u8d77\u6765\u7528\u4e86 clang \u505a\u6e90\u7801\u8bc6\u522b\u3002\u3002<br \/>\u662f\u4e0d\u662f\u53ef\u4ee5\u505a\u6210 clang plugin \u7684\u5f62\u5f0f\u5462\uff1f\u6bd5\u7adf\u5199\u6ce8\u91ca\u770b\u8d77\u6765\u6d77\u66d9\u4e0d\u592a\u81ea\u7136\uff08                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5283362\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : gyf304 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @codehz \u5199\u6ce8\u91ca\u8fd8\u662f\u6709\u5fc5\u8981\u7684 \u56e0\u4e3a\u4e00\u4e2a\u5934\u6587\u4ef6\u53ef\u80fd\u53ea\u8981 1 \u4e2a\u7c7b\u578b\u9700\u8981\u751f\u6210 \u8fd8\u6709\u5c31\u662f\u5bf9\u4e8e struct field \u7684\u6807\u8bb0 \u4f8b\u5982\u6539 key\uff0c\u6216\u8005\u4e0d\u8f93\u51fa\u67d0\u4e00\u4e2a field \u8fd9\u4e2a\u5176\u5b9e\u6709\u70b9\u501f\u9274\u4e86 golang \u7684 struct tag                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5283363\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @gyf304 #3 \u5176\u5b9e\u6211\u7684\u610f\u601d\u662f\u505a\u6210\u81ea\u5b9a\u4e49 attribute                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5283364\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CismonX <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @codehz \u6211\u89c9\u5f97\u81ea\u5b9a\u4e49 attribute\uff0c\u4e0d\u5982\u4e3b\u7684\u8fd9\u79cd\u5b9e\u73b0\u65b9\u5f0f<\/p>\n<p>\u9996\u5148\uff0c__attribute__ \u5173\u952e\u5b57\u662f gcc \u72ec\u6709\u7684\uff08\u867d\u7136 clang \u8fd9\u79cd\u4e0e gcc \u9ad8\u5ea6\u517c\u5bb9\u7684\u7f16\u8bd1\u5668\u4e5f\u652f\u6301\uff09\uff0c\u6240\u4ee5\u4ece\u517c\u5bb9\u89d2\u5ea6\u6765\u770b\u5e76\u4e0d\u597d\u3002\u518d\u52a0\u4e0a\u8fd9\u662f\u4e00\u4e2a clang plugin\uff0c\u90a3\u5c31\u66f4\u9ebb\u70e6\u4e86\u3002\u5373\u4f7f\u7528\u7684\u5c31\u662f clang\uff0c\u4e3a\u4e86\u5728 plugin \u4e0d\u5b58\u5728\u7684\u65f6\u5019\u4e0d\u62a5 warning \uff08-Wunknown-attributes \uff09\uff0c\u9700\u8981\u68c0\u6d4b\u90a3\u4e2a\u81ea\u5b9a\u4e49 attribute \u662f\u5426\u5b58\u5728\uff0c\u800c\u8fd9\u4e0d\u80fd\u7b80\u5355\u5730\u7528\u4e00\u4e2a #ifdef \u5b9e\u73b0\uff0c\u800c\u662f\u9700\u8981\u4f9d\u9760\u6784\u5efa\u811a\u672c\uff08\u53c2\u8003 AX_GCC_FUNC_ATTRIBUTE \u7684\u5b9e\u73b0\uff0c\u662f\u6784\u9020\u4e00\u6bb5\u5e26\u6709\u6307\u5b9a attribute \u7684\u4ee3\u7801\uff0c\u7136\u540e\u5c1d\u8bd5\u7f16\u8bd1\uff0c\u770b\u770b\u6709\u6ca1\u6709 warning \uff09\u3002<\/p>\n<p>\u5176\u6b21\uff0cclang plugin \u8fd9\u79cd\u4e1c\u897f\uff0c\u5b83\u5b58\u5728\u7684\u4e3b\u8981\u4ef7\u503c\u5728\u4e8e\u5e72\u9884\u7f16\u8bd1\u8fc7\u7a0b\u3002\u800c\u4e3b\u8fd9\u4e2a\u9879\u76ee\u53ea\u9700\u8981\u5206\u6790\u4ee3\u7801\uff0c\u6240\u4ee5\u6ca1\u6709\u5fc5\u8981\u91c7\u7528\u8fd9\u79cd\u4fb5\u5165\u6027\u5f3a\u7684\u5b9e\u73b0\u3002\u66fe\u7ecf\u89c1\u8fc7\u4e00\u4e2a\u7c7b\u4f3c\u7684\u9879\u76ee\uff0c\u5b9e\u73b0\u4e86\u81ea\u5b9a\u4e49 #pragma\uff0c\u4e5f\u662f\u5b58\u5728\u8fd9\u4e2a\u95ee\u9898\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5283365\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CismonX #5 (\u4f46\u662f\u597d\u5904\u5c31\u662f\u53ef\u4ee5\u4e0d\u7528\u843d\u76d8\uff0c\u4e0d\u9700\u8981\u5b9e\u9645\u7684\u751f\u6210\u6587\u4ef6\u3002\u3002\u3002<br \/>\u53ef\u4ee5\u505a\u6210\u591a\u79cd\u6a21\u5f0f\uff0c\u6bd5\u7adf\u5982\u679c\u9879\u76ee\u5df2\u7ecf\u4f9d\u8d56\u4e8e clang \u63d2\u4ef6\u7684\u65f6\u5019\uff0c\u5c31\u4e0d\u9700\u8981\u5728\u610f\u518d\u591a\u4e00\u4e2a\u4e86\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Show V2EX: cmarsh&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/343176"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343176"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/343176\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}