Java解析嵌套的JSON字符串
直接代码举例说明,需要json.jar包。
执行结果:
msg:Success
直接代码举例说明,需要json.jar包。
Maven依赖:
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
示例代码:
String jsonstr = "{\"sign\":\"ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE\"," +
"\"alipay_fund_trans_toaccount_transfer_response\":{" +
"\"pay_date\":\"2013-01-01 08:08:08\"," +
"\"code\":\"10000\"," +
"\"order_id\":\"20160627110070001502260006780837\"," +
"\"msg\":\"Success\"," +
"\"out_biz_no\":\"3142321423432\"}}";
JSONObject joResult = new JSONObject(jsonstr);
JSONObject joAftttr = (JSONObject) joResult.get("alipay_fund_trans_toaccount_transfer_response");
System.out.println("msg:" + joAftttr.getString("msg"));
执行结果:
msg:Success