{"id":8637,"date":"2022-08-19T08:25:44","date_gmt":"2022-08-19T00:25:44","guid":{"rendered":"https:\/\/www.hefeiyu.com\/?p=8637"},"modified":"2022-08-19T08:34:32","modified_gmt":"2022-08-19T00:34:32","slug":"tiptop%e8%b0%83%e7%94%a8java%e8%a7%a3%e6%9e%90json%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.hefeiyu.com\/?p=8637","title":{"rendered":"tiptop\u8c03\u7528java\u89e3\u6790json\u6848\u4f8b"},"content":{"rendered":"<p>tiptop\u76844gl\u73af\u5883\u9ed8\u8ba4\u4e0d\u652f\u6301\u89e3\u6790jaon\u6570\u636e\uff0c\u901a\u8fc7\u5bfc\u5165java\u5305\uff0c\u53ef\u4ee5\u5b9e\u73b0\u89e3\u6790\uff0c\u4ee5\u4e0b\u662f\u5b9e\u9645\u6848\u4f8b<\/p>\n<p>\u4e00\uff1a\u73af\u5883<\/p>\n<p>1\uff1aGP\u73af\u5883\uff1aTOPGP 5.2\u53ca\u4ee5\u4e0a<\/p>\n<p>2\uff1ajar\u5305\uff1a<a href=\"https:\/\/mvnrepository.com\/artifact\/com.alibaba\/fastjson\">fastjson.jar<\/a> &lt;\u6b64\u5305\u662f\u963f\u91cc\u5f00\u6e90\u7684jar\u5305\u3002\u4ee5\u540d\u5b57\u767e\u5ea6\u4e00\u4e0b\u5c31\u6709&gt;<\/p>\n<p>\u4e8c\uff1a\u5bfc\u5165\u65b9\u5f0f<\/p>\n<p>1\uff1a\u5c06fastjson.jar\u5305\u4e0b\u8f7d\u4e0b\u6765\uff0c\u5bfc\u5165\/u1\/topprod\/tiptop\/ds4gl2\/bin\u76ee\u5f55<\/p>\n<p>2\uff1a\u6253\u5f00\/u1\/topprod\/tiptop\/ds4gl2\/bin\/tiptop_env\u6587\u4ef6\uff0c\u5728CLASSPATH\u4e0a\u6dfb\u52a0$TOP\/ds4gl2\/bin\/fastjson.jar\u8fd9\u4e00\u6bb5\uff08\u6ca1\u6709CLASSPATH\u53ef\u4ee5\u76f4\u63a5\u5728\u672b\u5c3e\u52a0\uff09\uff0c\u5982\u4e0b\uff1a\u6dfb\u52a0\u5b8c\u6bd5\u540e\u4fdd\u5b58<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">CLASSPATH=$TOP\/ds4gl2\/bin\/fastjson.jar:$TOP\/ds4gl2\/bin\/javaad\/jar\/code.jar:$TOP\/ds4gl2\/bin\/javaad\/jar\/core.jar;export CLASSPATH<\/code><\/pre>\n<p>3\uff1a\u4fdd\u5b58\u540e\u5237\u65b0\u4e0b\u73af\u5883\u53d8\u91cf source tiptop_env\uff0c\u91cd\u65b0\u767b\u5f55\u540e\uff0c\u5c31\u53ef\u4ee5\u53bb\u5c1d\u8bd5\u4f7f\u7528java\u5305\u89e3\u6790json\u4e86\uff0c\u5b9e\u9645\u6848\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\"># Prog. Version..: '5.25.03-11.07.14(00006)'     #\r\n#\r\n# Pattern name...: cws_json.4gl\r\n# Descriptions...: \r\n# Date &amp; Author..: 2019\/04\/17 By caozq\r\n# Usage..........: 4GL\u89e3\u6790json\u8303\u4f8b\r\nIMPORT util\r\nIMPORT JAVA com.alibaba.fastjson.JSON\r\nIMPORT JAVA com.alibaba.fastjson.JSONArray\r\nIMPORT JAVA com.alibaba.fastjson.JSONObject\r\n\r\nDATABASE ds\r\n \r\nGLOBALS \"..\/..\/config\/top.global\"    #FUN-7C0053\r\n\r\nFUNCTION cws_json()\r\nDEFINE json_str RECORD \r\n\tcust_num   INTEGER,\r\n\tcust_name  VARCHAR(30),\r\n\torder_ids  JSONArray,\r\n\tarr_list   JSONArray\r\n\tEND RECORD\r\nDEFINE json_obj    JSONObject\r\nDEFINE js STRING\r\nDEFINE aa   STRING\r\nDEFINE bb   STRING\r\nDEFINE l_cnt,i   INTEGER\r\nDEFINE obj    JSONObject\r\n\r\nLET js = '{\"cust_num\":123,\"cust_name\":\"caozq\",\"order_ids\":[234,567,789],\"arr_list\":[{\"aa\":\"aa\",\"bb\":\"cc\"},{\"aa\":\"aa1\",\"bb\":\"bb1\"}]}'\r\n\r\nLET json_obj = com.alibaba.fastjson.JSON.parseObject(js)\r\nLET json_str.cust_num = json_obj.getIntValue(\"cust_num\")\r\nLET json_str.cust_name = json_obj.getString(\"cust_name\")\r\nLET json_str.order_ids = json_obj.getJSONArray(\"order_ids\")\r\nLET json_str.arr_list = json_obj.getJSONArray(\"arr_list\")\r\n\r\nFOR i=0 TO json_str.order_ids.size()-1\r\n  LET l_cnt = json_str.order_ids.getIntValue(i)\r\nEND FOR\r\n\r\nFOR i=0 TO json_str.arr_list.size()-1\r\n  LET obj = json_str.arr_list.getJSONObject(i)\r\n  LET aa = obj.getString(\"aa\")\r\n  LET bb = obj.getString(\"bb\")\r\nEND FOR\r\n\r\nEND FUNCTION \r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.hefeiyu.com\">\u8d6b\u975e\u57df<\/a> &raquo; <a href=\"https:\/\/www.hefeiyu.com\/?p=8637\">tiptop\u8c03\u7528java\u89e3\u6790json\u6848\u4f8b<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>tiptop\u76844gl\u73af\u5883\u9ed8\u8ba4\u4e0d\u652f\u6301\u89e3\u6790jaon\u6570\u636e\uff0c\u901a\u8fc7\u5bfc\u5165java\u5305\uff0c\u53ef\u4ee5\u5b9e\u73b0\u89e3\u6790\uff0c\u4ee5\u4e0b\u662f\u5b9e\u9645\u6848\u4f8b \u4e00\uff1a\u73af\u5883 1\uff1aGP\u73af\u5883\uff1aTOPGP 5.2\u53ca\u4ee5\u4e0a 2\uff1ajar\u5305\uff1afastjson.jar &lt;\u6b64\u5305\u662f\u963f\u91cc\u5f00\u6e90\u7684jar\u5305\u3002\u4ee5\u540d\u5b57\u767e\u5ea6\u4e00\u4e0b\u5c31\u6709&#038;gt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[490,26],"tags":[1073,627,10],"class_list":["post-8637","post","type-post","status-publish","format-standard","hentry","category-490","category-4gl","tag-dsgl","tag-jar","tag-tiptop"],"_links":{"self":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/8637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8637"}],"version-history":[{"count":3,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/8637\/revisions"}],"predecessor-version":[{"id":8640,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=\/wp\/v2\/posts\/8637\/revisions\/8640"}],"wp:attachment":[{"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hefeiyu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}