㈠ 請大神幫助,java如何解析json數據
java首先導入以下一個包
json-lib-2.3-jdk15.jar
commons-beanutils-1.7.0.jar
commons-httpclient-3.1.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
commons-collections-3.1.jar
ezmorph-1.0.3
String dataStr = "{\"resultcode\":\"200\",.......}";
JSONObject json = JSONObject.fromObject(dataStr );
String resultcode = json.get('resultcode');
就是這樣獲取的;
String result = json.get('resultcode');
JSONObject resultJson = JSONObject.fromObject(result );
嵌套的json必須在重新解析
去了解下 JSON的相關api吧
㈡ java解析json數據
final String jsonData = "{\"success\":true}";
JSONObject jsonObj = JSONObject.fromObject(jsonData);
boolean success = jsonObj.getBoolean("success");