在pom文件中加入依赖 <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.7.0</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>net.sf.ezmorph</groupId> <artifactId>ezmorph</artifactId> <version>1.0.3</version>
</dependency>
代码,创建对象JSONObject jsonObj;result为一个json串jsonObj = JSONObject.fromObject(result);
if("true".equalsIgnoreCase(jsonObj.getString("success"))) { JSONArray sAddrJsonArray = JSONArray.fromObject(jsonObj.getString("transactions")); for (int i = 0; i < sAddrJsonArray.size(); i++) { JSONObject amount = JSONObject.fromObject(sAddrJsonArray.getJSONObject(i).getString("amount")); // if("MAE".equals(amount.getString("currency"))){ Transaction transaction = new Transaction(); transaction.setDate(UnixDate2TimeStamp(sAddrJsonArray.getJSONObject(i).getString("date"),"yyyy-MM-dd HH:mm:ss")); transaction.setHash(sAddrJsonArray.getJSONObject(i).getString("hash")); transaction.setType(sAddrJsonArray.getJSONObject(i).getString("type")); transaction.setFee(sAddrJsonArray.getJSONObject(i).getString("fee")); transaction.setResult(sAddrJsonArray.getJSONObject(i).getString("result")); transaction.setClient_resource_id(sAddrJsonArray.getJSONObject(i).getString("client_resource_id")); transaction.setMemos(sAddrJsonArray.getJSONObject(i).getString("memos")); String counterparty = sAddrJsonArray.getJSONObject(i).getString("counterparty"); transaction.setCounterparty(counterparty); set.add(counterparty); transaction.setEffects(sAddrJsonArray.getJSONObject(i).getString("effects")); transaction.setAmount_value(amount.getString("value")); transaction.setAmount_currency(amount.getString("currency")); transaction.setIssuer(amount.getString("issuer")); transactionService.insert(transaction); // } } }