Java中如何操作JSON格式的字串

來源:互聯網
上載者:User

1. 首先需要一個類支援 JSONObject類,該類需要外部JAR包支援,下面是

  jettison-1.0.jar包:http://www.kuaipan.cn/file/id_21487635482542624.htm

 

2. 下面在代碼中示範如何用

 1 import org.codehaus.jettison.json.JSONException; 2 import org.codehaus.jettison.json.JSONObject; 3  4 public class HelloWorldTest { 5     public static void main(String[] args) { 6         String jsonStr = "{\"b_action\":\"xts.run\",\"m\":\"portal/report-viewer.xts\",\"method\":\"execute\"," 7                 + "\"ui.action\":\"run\",\"ui.tool\":\"CognosViewer\",\"ui.object\":\"/content/package[@name='zjfx_bdgc']/report[@name='a']\"," 8                 + "\"ZTBM\":\"000010000200001000010000100001\",\"MBBM\":\"001\",\"p_d\":\"2011010000100001\"," 9                 + "\"run.prompt\":\"false\",\"ZBYQ_DJ\":\"1111\",\"BDGC_DYDJ\":\"22222\",\"BDGC_JSXZ\":\"01\","10                 + "\"JSZB_BDZXS\":\"01,02,03\",\"PDXS_GYC_PDZZXH\":\"02\",\"ZBYQ_BQTS1\":\"1\",\"ZBYQ_BQTS2\":\"2\","11                 + "\"ZBYQ_DTRL1\":\"3\",\"ZBYQ_DTRL2\":\"4\",\"JGJS_JTTZ1\":\"5\","12                 + "\"JGJS_JTTZ2\":\"6\",\"btnsearch\":\"查詢\",\"btnreset\":\"重設\"}";13         14         try {15             JSONObject obj = new JSONObject(jsonStr);16             String b_action = (String)obj.get("b_action");17             System.out.println(b_action);18         } catch (JSONException e) {19             e.printStackTrace();20         }21     }22 }

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.