{"id":690,"date":"2012-05-22T00:04:32","date_gmt":"2012-05-21T16:04:32","guid":{"rendered":"http:\/\/www.gejo.in\/?p=690"},"modified":"2012-05-22T00:04:32","modified_gmt":"2012-05-21T16:04:32","slug":"%e4%bd%bf%e7%94%a8cjson%e8%a7%a3%e6%9e%90jsonnote","status":"publish","type":"post","link":"https:\/\/www.mujins.com\/?p=690","title":{"rendered":"\u4f7f\u7528cJson[C\u8bed\u8a00]\u89e3\u6790json.."},"content":{"rendered":"<p>\u6700\u8fd1\u5f88\u5fd9\uff0c\u9879\u76ee\u7684\u9700\u8981\uff0c\u5148\u662f\u641e\u4e86\u641eSOAP,\u4f7f\u7528gSoap\u6765\u5904\u7406Web service\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\uff0c\u786e\u5b9e\u76f8\u5f53\u65b9\u4fbf\uff0c\u6b63\u5f53\u641e\u5f97\u83ab\u540d\u5176\u5999\u65f6\uff0c\u8fce\u6765\u4e86\u4e94\u4e00\u5c0f\u957f\u5047\uff0c\u56de\u4e86\u8d9f\u5bb6\uff0c\u4e00\u5468\u4e4b\u540e\u56de\u6765\uff0c\u63a5\u5230\u7684\u662f\u7528json&#8230;..JSON\uff1fXML?SOAP&#8230;?\u4f7f\u7528gSoap,json-c,libjson?\u989d\u6ef4\u795e\u554a\uff08\u8fd9\u5176\u5b9e\u4e0d\u662f\u9655\u897f\u8bdd\uff0c\u539f\u610f\uff1aMY GOD!\uff09\u600e\u4e48\u529e\uff0c\u641e\u5457&#8230; <strong>JSON<\/strong>(JavaScript Object Notation): \u00a0 \u00a0\u00a0<a href=\"http:\/\/www.json.org\/json-zh.html\">http:\/\/www.json.org\/json-zh.html<\/a> <strong>SOAP<\/strong>(Simple Object Access Protocol\u00a0): \u00a0<a href=\"http:\/\/www.w3school.com.cn\/soap\/index.asp\">http:\/\/www.w3school.com.cn\/soap\/index.asp<\/a>\u00a0 \u00a0 <a href=\"http:\/\/zh.wikipedia.org\/wiki\/SOAP\">http:\/\/zh.wikipedia.org\/wiki\/SOAP<\/a> \u5bf9\u4e8e\u51fa\u73b0\u7684\u6240\u6709\u5de5\u5177\uff0c\u65b9\u6cd5\uff0c\u5e93\u53ef\u4ee5Google\u4e4b\uff0c\u6211\u53ea\u662f\u628a\u6211\u7528json\u7684\u4e00\u4e9b\u4f53\u4f1a\u8bb0\u5f55\u4e0b\u6765\uff0c\u6211\u53ea\u662f\u4f7f\u7528C\u5bf9\u7b80\u5355json\u62a5\u6587\u89e3\u6790\uff0c\u6548\u7387\u8981\u8003\u8651\u3002<!--more--> <a href=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2012\/05\/c_plus_plus_wallpaper_by_captjc-d3y0i7e.jpg\" data-lightbox=\"gal[690]\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-691\" title=\"c_plus_plus_wallpaper_by_captjc-d3y0i7e\" src=\"https:\/\/www.gigiwangs.com\/wp-content\/uploads\/2012\/05\/c_plus_plus_wallpaper_by_captjc-d3y0i7e.jpg\" alt=\"\" width=\"600\" height=\"337\" \/><\/a> <strong>I.\u7f16\u8bd1Jansson<\/strong>\u6362\u8fc7\u597d\u591a\u79cd\u5f00\u6e90\u5e93\u6216code\uff1ajson-c \u770b\u8d77\u6765\u786e\u5b9e\u4e0d\u9519\uff0c\u4f3c\u4e4e\u517c\u5bb9\u6027\u5dee\u70b9\u513f\uff0cLinux\u4e0a\u4e00\u5207\u987a\u5229\uff0c\u5728AIX\u4e0a\u5c31\u662f\u7f16\u8bd1\u4e0d\u8fc7\uff0c\u4fee\u6539\u4e4b\u540e\uff0c\u4e00\u5230\u521b\u5efa\u6216\u8bbf\u95ee\u5bf9\u8c61\u603b\u4f1a\u83ab\u540ddown\u6389\uff0c\u53ea\u80fdPass\u6389\uff1b\u7136\u540e\u7684libjson\uff0cmjson&#8230;\u6211\u90fd\u5fd8\u8bb0\u600e\u4e48\u5c31\u6ca1\u7528\u5b83\u4eec\uff0c\u6700\u540e\u7528\u4e86Jansson\uff0c\u770b\u8d77\u6765\u786e\u5b9e\u7b80\u5355\uff0c\u53ea\u6709cJSON.h\u548ccJSON.c,\u628a\u5b83\u4eec\u5305\u542b\u5230\u5de5\u7a0b\u4e2d\u5c31OK\u4e86\uff0cMakefile\u52a0\u5165\uff0c\u7f16\u8bd1\uff0cOh\uff0cSHIT! \u51fa\u9519\uff1a<\/p>\n<pre class=\"brush:c\">    ERROR: Undefined symbol: .__floor<\/pre>\n<pre>AIX\u771f\u662f\u7237\uff01\u67e5\u9605\u597d\u591a\u8d44\u6599\uff0c\u4f3c\u4e4e\u54b1\u7684xlc\u7f16\u8bd1\u5668\u592ashit\u4e86\uff0c\u597d\u50cf\u4f7f\u7528gcc\u4e5f\u8fd9\u6837...\u90a3\u4e48\u4e00\u4e2a\u8bba\u575b\u4e0a\u770b\u5230\uff08\u5176\u5b83\u4e0d\u77e5\u9053\u6cd5\u6587\u8fd8\u662f\u4ec0\u4e48\u7684<a href=\"http:\/\/www.developpez.net\/\">http:\/\/www.developpez.net<\/a>\uff09\uff0cAIX\u4e2dinclude\u5934\u6587\u4ef6math.h&gt;&gt;&gt;&gt;&gt;<\/pre>\n<pre class=\"brush:c\">#ifdef __MATH__\n#define acos(__x)         __acos(__x)\n#define asin(__x)         __asin(__x)\n#define atan(__x)         __atan(__x)\n#define atan2(__x,__y)      __atan2(__x,__y)\n#define cos(__x)          __cos(__x)\n#define exp(__x)          __exp(__x)\n#define fabs(__x)         __fabs(__x)\n#define log(__x)          __log(__x)\n#define log10(__x)        __log10(__x)\n#define sin(__x)          __sin(__x)\n#define sqrt(__x)         __sqrt(__x)\n#define tan(__x)          __tan(__x)<\/pre>\n<pre>\u5c06\u5176\u4e2d\uff1a<\/pre>\n<pre class=\"brush:c\">#ifdef __IBMC__\n#if (__xlC__ &gt;= 0x0600) \/* VAC version 6 and above *\/\n#define floor(__x)        __floor(__x)\n#define ceil(__x)         __ceil(__x)\n#endif \/* __xlC__ &gt;= 0x0600 *\/\n#endif \/* __IBMC__ *\/<\/pre>\n<p>\u4fee\u6539\u4e3a\uff1a<\/p>\n<pre class=\"brush:c\">#ifdef __IBMC__\n#if (__xlC__ &gt;= 0x0600) \/* VAC version 6 and above *\/\n#define floor(__x)        floor(__x)\n#define ceil(__x)         ceil(__x)\n#endif \/* __xlC__ &gt;= 0x0600 *\/\n#endif \/* __IBMC__ *\/<\/pre>\n<p>\u7f16\u8bd1\u901a\u8fc7&#8230;&#8230; <strong>II.Jansson\u89e3\u6790json<\/strong>\u8fd9\u91cc\u4e0d\u591a\u8bf4\u4e86\uff0c\u62c5\u5fc3\u8bef\u4eba\u5b50\u5f1f..\u7b80\u5355\u51e0\u70b9\uff0c\u539f\u6765\u4ee3\u7801\u4e0d\u63d0\u4f9blong long\u89e3\u6790\uff0c\u4e0d\u63d0\u4f9b\u76f4\u63a5\u904d\u5386&#8230;\u7531\u4e8e\u6211\u7528\u5230\u89e3\u6790\uff0c\u53ea\u662f\u628a\u6807\u7b7e\u503c\u53d6\u51fa\u6765\uff1b\u628a\u4ee3\u7801\u8d34\u51fa\u6765\uff0c\u53ea\u662f\u7b80\u5355\u6d4b\u8bd5..\u5934\u6587\u4ef6cJSON.h\u548csource cJSON.c\u6309\u7167\u6211\u7684\u9700\u6c42\u505a\u4e86\u66f4\u6539\uff0c\u5c31\u4e0d\u8d34\u51fa\u6765\u4e86\uff0c\u4ee5\u4e0bcode\u4f9b\u53c2\u8003\u6d4b\u8bd5&#8230;.[\u524d\u65b9\u6709\u602a\u517d&#8230;.]<\/p>\n<pre class=\"brush:c\">cJSON* pRoot = cJSON_Parse ( jsonString );\n    while ( pRoot )\n    {\n        do\n        {\n            pItem = cJSON_GetObjectItem ( pRoot, \"Code\");\n            if(pItem){\n                switch(type)\n                {\n                    case 0:\n                        strcpy(out,pItem-&gt;valuestring);\n                        break;\n                     case 1:\n                        sprintf(out,\"%d\",pItem-&gt;valueint);\n                        break;\n                     case 2:\/\/long long\n                        sprintf(out,\"%lld\",pItem-&gt;valuellong);\n                        break;\n                     case 3:\/\/double\n                        sprintf(out,\"%lf\",pItem-&gt;valuedouble);\n                        break;\n                     case 4: \/\/array\n                        nCount = cJSON_GetArraySize( pItem); \/\/\u83b7\u53d6pArray\u6570\u7ec4\u7684\u5927\u5c0f,\u4ec5\u5bf9\u5b57\u7b26\u4e32\u5143\u7d20\uff1f\n                        for( i= 0; i &lt; nCount; i++)\n                        {\n                            pArrayItem = cJSON_GetArrayItem(pItem, i);\n                            strcat(out,cJSON_Print( pArrayItem));\n                           \/\/ sprintf(out,\"%s\",out,pArrayItem);\n                        }\n                        break;\n                }\n            }\n            else if(pRoot-&gt;next)\n               pRoot=pRoot-&gt;next;\n            else break;\n\n        }while(!pItem&amp;&amp;pRoot);     \n        if(pRoot-&gt;child)\n           pRoot=pRoot-&gt;child;\n     }<\/pre>\n<pre>\u00a0   \u7ee7\u7eed\u5427\uff0c\u597d\u591a\u6d3b\u7b49\u7740\u505a..\u5fd9\u554a\uff0c\u7d2f\u554a...\u5bf9\u4e86\u8fd8\u8981\u7528\u5230Curl..<\/pre>\n<pre>    \u6b22\u8fce\u6d4f\u89c8\uff0c\u96be\u514d\u758f\u6f0f\uff0c\u8f6c\u8f7d\u9700\u8c28\u614e....<\/pre>\n<pre> \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u5409\u5409\u535a\u5ba2gejo.in<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5f88\u5fd9\uff0c\u9879\u76ee\u7684\u9700\u8981\uff0c\u5148\u662f\u641e\u4e86\u641eSOAP,\u4f7f\u7528gSoap\u6765\u5904\u7406Web service\u670d\u52a1\u7aef\u548c\u5ba2\u6237\u7aef\uff0c\u786e\u5b9e\u76f8\u5f53\u65b9\u4fbf\uff0c\u6b63\u5f53\u641e\u5f97\u83ab\u540d\u5176\u5999\u65f6\uff0c\u8fce\u6765\u4e86\u4e94\u4e00\u5c0f\u957f\u5047\uff0c\u56de\u4e86\u8d9f\u5bb6\uff0c\u4e00\u5468\u4e4b\u540e\u56de\u6765\uff0c\u63a5\u5230\u7684\u662f\u7528json&#8230;..JSON\uff1fXML?SOAP&#8230;?\u4f7f\u7528gSoap,json-c,libjson?\u989d\u6ef4\u795e\u554a\uff08\u8fd9\u5176\u5b9e\u4e0d\u662f\u9655\u897f\u8bdd\uff0c\u539f\u610f\uff1aMY GOD!\uff09\u600e\u4e48\u529e\uff0c\u641e\u5457&#8230; JSON(JavaScript Object Notation): \u00a0 \u00a0\u00a0http:\/\/www.json.org\/json-zh.html SOAP(Simple Object Access Protocol\u00a0): \u00a0http:\/\/www.w3school.com.cn\/soap\/index.asp\u00a0 \u00a0 http:\/\/zh.wikipedia.org\/wiki\/SOAP \u5bf9\u4e8e\u51fa\u73b0\u7684\u6240\u6709\u5de5\u5177\uff0c\u65b9\u6cd5\uff0c\u5e93\u53ef\u4ee5Google\u4e4b\uff0c\u6211\u53ea\u662f\u628a\u6211\u7528json\u7684\u4e00\u4e9b\u4f53\u4f1a\u8bb0\u5f55\u4e0b\u6765\uff0c\u6211\u53ea\u662f\u4f7f\u7528C\u5bf9\u7b80\u5355json\u62a5\u6587\u89e3\u6790\uff0c\u6548\u7387\u8981\u8003\u8651\u3002<\/p>\n","protected":false},"author":1,"featured_media":691,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,21,5,17],"tags":[24],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts\/690"}],"collection":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=690"}],"version-history":[{"count":0,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/wp\/v2\/posts\/690\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mujins.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}