{"id":769,"date":"2023-10-25T15:11:50","date_gmt":"2023-10-25T07:11:50","guid":{"rendered":"http:\/\/www.inhhh.com\/blog\/?p=769"},"modified":"2023-10-25T21:50:55","modified_gmt":"2023-10-25T13:50:55","slug":"linux%e4%b8%adjson%e5%ae%89%e8%a3%85%e5%8f%8a%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.inhhh.com\/blog\/?p=769","title":{"rendered":"Linux\u4e2dJSON\u5b89\u88c5\u53ca\u4f7f\u7528"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/www.cnblogs.com\/MIUMIUBLING\/p\/16669414.html\">Linux\u4e2dJSON\u5b89\u88c5\u53ca\u4f7f\u7528<\/a><\/h2>\n\n\n\n<p>1.\u5b98\u7f51\u4e0b\u8f7djson-cpp\uff0c\u53ef\u4ee5\u53bbsourceforge\u6216github<\/p>\n\n\n\n<p><a href=\"https:\/\/sourceforge.net\/projects\/jsoncpp\/files\/\">https:\/\/sourceforge.net\/projects\/jsoncpp\/files\/<\/a><\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e0b\u8f7d\u7684\u662fjsoncpp-src-0.5.0.tar.gz<\/p>\n\n\n\n<p>2.\u4e0b\u8f7dscons<\/p>\n\n\n\n<p>http:\/\/sourceforge.net\/projects\/scons\/files\/scons\/2.1.0\/scons-2.1.0.tar.gz\/download<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e0b\u8f7d\u7684\u662fscons-2.1.0.tar.gz<\/p>\n\n\n\n<p>3.\u89e3\u538b\u521a\u521a\u4e0b\u8f7d\u7684scons-2.1.0.tar.gz<\/p>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1atar -zvxf scons-2.1.0.tar.gz<\/p>\n\n\n\n<p>\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u9009\u62e9\u89e3\u538b\u5730\u5740<\/p>\n\n\n\n<p>4.\u8fdb\u5165\u521a\u521a\u89e3\u538b\u7684scons-2.1.0\u6587\u4ef6\u5939\u4e2d<\/p>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1asudo python setup.py install<\/p>\n\n\n\n<p>5.\u89e3\u538b\u4e0b\u8f7d<br><a href=\"https:\/\/codeload.github.com\/open-source-parsers\/jsoncpp\/tar.gz\/refs\/tags\/1.9.5\">https:\/\/codeload.github.com\/open-source-parsers\/jsoncpp\/tar.gz\/refs\/tags\/1.9.5<\/a><br>\u597d\u7684jsoncpp-src-1.9.5.tar.gz<\/p>\n\n\n\n<p>tar -zvxf jsoncpp-src-1.9.5.tar.gz<\/p>\n\n\n\n<p>\u540c\u6837\u7684\uff0c\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u9009\u62e9\u89e3\u538b\u5730\u5740<\/p>\n\n\n\n<p>6.\u8fdb\u5165\u521a\u521a\u89e3\u538b\u7684jsoncpp-src-1.9.5\u6587\u4ef6\u5939\u4e2d<\/p>\n\n\n\n<p>cd jsoncpp-1.9.5 mkdir build &amp;&amp; cd build cmake .. -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON make sudo make install<\/p>\n\n\n\n<p>7.\u5c06 \/jsoncpp-src-0.5.0\/include \u76ee\u5f55\u4e0b\u7684json\u6587\u4ef6\u5939\u62f7\u8d1d\u5230\/usr\/include<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u7684\u7535\u8111\u4e0d\u80fd\u76f4\u63a5\u590d\u5236\u7c98\u8d34\u6587\u4ef6\u5939\uff0c\u56e0\u6b64\u4f7f\u7528cp \u2013r\u547d\u4ee4<\/p>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u5982\u4e0b\uff1acp \u2013r \/mnt\/share\/jsoncpp-src-0.5.0\/include\/json \/usr\/include<\/p>\n\n\n\n<p>8.\u5c06 \/jsoncpp-src-0.5.0\/libs\/linux-gcc-5.3.1 \u76ee\u5f55\u4e0b\u7684libjson_linux-gcc-5.3.1_libmt.a \u62f7\u8d1d\u5230 \/usr\/local\/lib \u4e0b \uff08\u4e3a\u4fbf\u4e8e\u4f7f\u7528\uff0c\u53ef\u5c06\u5176libjson_linux-gcc-5.3.1_libmt.a\u91cd\u547d\u540d\u4e3a\u7b80\u77ed\u4e00\u70b9\u7684libjson.a\uff09<\/p>\n\n\n\n<p>\u540c\u6837\uff0c\u4f7f\u7528cp \u2013r\u547d\u4ee4\u590d\u5236\u6587\u4ef6<\/p>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u5982\u4e0b\uff1acp \u2013r \/mnt\/share\/jsoncpp-src-0.5.0\/libs\/linux-gcc-5.3.1\/libjson_linux-gcc-5.3.1_libmt.a \/usr\/local\/lib<\/p>\n\n\n\n<p>\u91cd\u547d\u540d\u53ef\u4ee5\u4f7f\u7528mv\u547d\u4ee4\u6216rename\u547d\u4ee4<\/p>\n\n\n\n<p>9.\u7b80\u5355\u5199\u4e00\u4e2a\u6d4b\u8bd5\u4ee3\u7801 testjson.cpp<\/p>\n\n\n\n<p>#include&lt;iostream&gt;<\/p>\n\n\n\n<p>#include&lt;json\/json.h&gt;<\/p>\n\n\n\n<p>using namespace std;<\/p>\n\n\n\n<p>int main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>string test=&#8221;{\\&#8221;id\\&#8221;:2021,\\&#8221;name\\&#8221;:\\&#8221;Happy New Year\\&#8221;}&#8221;;<\/p>\n\n\n\n<p>Json::Reader reader;<\/p>\n\n\n\n<p>Json::Value value;<\/p>\n\n\n\n<p>if(reader.parse(test,value)){<\/p>\n\n\n\n<p>if(!value[&#8220;id&#8221;].isNull()){<\/p>\n\n\n\n<p>cout&lt;&lt;value[&#8220;id&#8221;].asInt()&lt;&lt;endl;<\/p>\n\n\n\n<p>cout&lt;&lt;value[&#8220;name&#8221;].asString()&lt;&lt;endl;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>return 0;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>10.\u7f16\u8bd1\u521a\u521a\u5199\u7684testjson.cpp<\/p>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u547d\u4ee4\uff1a g++ testjson.cpp \u2013o testjson \/usr\/local\/lib\/libjson_linux-gcc-5.3.1_libmt.a<\/p>\n\n\n\n<p>\uff08\u6211\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u662f\u4fdd\u9669\uff09<\/p>\n\n\n\n<p>\u7136\u540e\u8f93\u5165\u547d\u4ee4\u8fd0\u884c\uff1a .\/testjson<\/p>\n\n\n\n<p>11.\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n\n\n\n<p>2021<\/p>\n\n\n\n<p>Happy New Year<\/p>\n\n\n\n<p>12. \u4e00\u4e9b\u5173\u4e8ejson\u4f7f\u7528\u5c0f\u7ed3<\/p>\n\n\n\n<p>\u6211\u4e2a\u4eba\u8ba4\u4e3ajson\u6587\u4ef6\u662f\u5b58\u50a8\u6570\u636e\u7684\u4e00\u79cd\u683c\u5f0f\u6587\u4ef6\uff0c\u800c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u201c\u5b57\u7b26\u4e32\u201d\u5bf9\u5176\u4e2d\u63d0\u53d6\u6240\u9700\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u4e3b\u8981\u4e3a\u8bfb\u53d6json\u6587\u4ef6\uff0c\u5199\u5165json\u6587\u4ef6<\/p>\n\n\n\n<p>\u6ce8\u610f\u5bf9\u4e8e\u4e8c\u7ef4\u4e09\u7ef4\u591a\u7ef4\u7684json\u6570\u636e\uff0c\u7528\u591a\u91cdJson::Value\u8bfb\u53d6\u5373\u53ef<br>====================================================================================\u65e0\u6cd5\u8fd0\u884c\uff0c\u7ed3\u5408\u53e6\u4e00\u7bc7<\/p>\n\n\n\n<p>\u8981\u5b89\u88c5jsoncpp,\u9996\u5148\u8981\u4e0b\u8f7d\u597dscons,\u518d\u53bb\u5b89\u88c5jsoncpp<\/p>\n\n\n\n<p>scons\u4e0b\u8f7d\u5730\u5740\uff1awget http:\/\/prdownloads.sourceforge<a href=\"http:\/\/lib.csdn.net\/base\/dotnet\" rel=\"noreferrer noopener\" target=\"_blank\">.NET<\/a>\/scons\/scons-2.2.0.tar.gz<\/p>\n\n\n\n<p>Jsoncpp \u4e0b\u8f7d\u5730\u5740&nbsp;http:\/\/sourceforge.net\/projects\/jsoncpp\/files\/latest\/download?_test=goal&nbsp;<\/p>\n\n\n\n<p>\u5b89\u88c5\u6b65\u9aa4\u5982\u4e0b\uff1a#tar -zxvf scons-2.1.0.tar.gz&nbsp;#cd scons-2.1.0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#python setup.py install<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#tar -zxvf jsoncpp-src-0.5.0.tar.gz<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#cd jsoncpp-src-0.5.0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#scons platform=linux-gcc<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#mv libs\/linux-gcc-4.4.7\/libjson_linux-gcc-4.4.7_libmt.so \/lib<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#ln \/lib\/libjson_linux-gcc-4.4.7_libmt.so \/lib\/libjson.so<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#mv include\/json\/ \/usr\/include\/<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#ldconfig<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#.\/bin\/linux-gcc-4.4.7\/test_lib_json<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u3010\u6ce8\u610f\u8fd9\u91cc\u7684\u7248\u672c\u53f7\u53ef\u80fd\u4e0d\u540c\u3011\u5148\u901a\u8fc7cd libs\u8fdb\u5165libs\u76ee\u5f55\uff0c\u518d\u7528\u201cls\u201d\u547d\u4ee4\u67e5\u770b\u81ea\u5df1\u7684\u7248\u672c\u53f7\uff0c\u7136\u540e\u5728\u4e0a\u8ff0\u6b65\u9aa4\u4e2d\u4fee\u6539\u6210\u81ea\u5df1\u7684\u7248\u672c\u53f7\u5373\u53ef<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;======================================================\u7b2c\u4e09\u7bc7https:\/\/www.csdn.net\/tags\/NtDaEgzsMzc2NjctYmxvZwO0O0OO0O0O.html<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">1. C++ json\u8bfb\u5199<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">1.1. rapidjson<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/Tencent\/rapidjson.git\n<\/code><\/pre>\n\n\n\n<p>\u5f85\u7eed<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.2. JsonCpp<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.2.1. \u5b89\u88c5\u548c\u7f16\u8bd1<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0b\u8f7d<\/li>\n<\/ol>\n\n\n\n<p>http:\/\/sourceforge.net\/projects\/jsoncpp\/files\/<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>\u4e0b\u8f7dscons<\/li>\n<\/ol>\n\n\n\n<p>http:\/\/sourceforge.net\/projects\/scons\/files\/scons\/2.1.0\/scons-2.1.0.tar.gz\/download<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li>\u89e3\u538bscons-2.1.0.tar.gz<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -zvxf scons-2.1.0.tar.gz\n<\/code><\/pre>\n\n\n\n<p>\u6211\u7684\u89e3\u538b\u5230\u4e86\/opt\/JSON\/scons-2.1.0\u76ee\u5f55\u4e0b\u4e86<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li>\u8fdb\u5165\u5230\u89e3\u538b\u76ee\u5f55scons-2.1.0\u4e0b\u9762\uff0c\u6267\u884c\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo python setup.py install\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li>\u89e3\u538bjsconcpp<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -zvxf jsoncpp-src-0.5.0.tar.gz\n<\/code><\/pre>\n\n\n\n<p>\u6211\u7684\u89e3\u538b\u5230\u4e86\/opt\/JSON\/jsoncpp-src-0.5.0\u4e0b<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li>\u8fdb\u5165\u5230jsoncpp\u89e3\u538b\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo scons platform=linux-gcc\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"7\">\n<li>\u62f7\u8d1d\u52a8\u6001\u5e93<br>\u5c06jsoncpp-src-0.5.0\/libs\/linux-gcc-4.9.1\/\u76ee\u5f55\u4e0b\u7684libjson_linux-gcc-4.9.1_libmt.a \u62f7\u8d1d\u5230\/usr\/local\/lib\/\u4e0b\uff0c\u5e76\u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\uff0c\u5c06\u5176\u91cd\u547d\u540d\u4e3alibjson.a<\/li>\n\n\n\n<li>\u5b9e\u4f8b<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream&gt;\n#include&lt;json\/json.h&gt;\n\nusing namespace std;\n\nint main()\n{\n    string test=\"{\\\"id\\\":1,\\\"name\\\":\\\"kurama\\\"}\";\n    Json::Reader  reader;\n    Json::Value   value;\n    \n    if(reader.parse(test,value))\n    {\n        if(!value&#91;\"id\"].isNull())\n        {\n            cout&lt;&lt;value&#91;\"id\"].asInt()&lt;&lt;endl;\n            cout&lt;&lt;value&#91;\"name\"].asString()&lt;&lt;endl;\n        }\n    }\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p><strong><code>g++ test.cpp -I include -L libs\/linux-gcc-9 -l json_linux-gcc-9_libmt<\/code><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4e2dJSON\u5b89\u88c5\u53ca\u4f7f\u7528 1.\u5b98\u7f51\u4e0b\u8f7djson-cpp\uff0c\u53ef\u4ee5\u53bbsourceforge\u6216github ht<\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"http:\/\/www.inhhh.com\/blog\/?p=769\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-769","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=769"}],"version-history":[{"count":3,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions"}],"predecessor-version":[{"id":772,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions\/772"}],"wp:attachment":[{"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=769"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.inhhh.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}