所用jar包,json-org.jar 下载地址:http://www.docjar.com/jar_detail/json-org.jar.html import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class JsonUtil { public static void main(String[] args) { String str="{\"name\":\"putixiaoshifu\",\"skills\":{\"java\":[\"jsp\",\"js\"]},\"hobbies\":{\"static\":[{\"morning\":\"music\",\"noon\":\"tvShows\"}],\"dynamic\":\"sports\"}}"; try { JSONObject j = new JSONObject(str); JSONObject jsonName = j.getJSONObject("skills"); System.out.println(jsonName); JSONArray jsonArray = jsonName.getJSONArray("java"); System.out.println(jsonArray); String a = (String) jsonArray.get(0); System.out.println(a); System.out.println("----------------------------------------------"); JSONObject hobbies = j.getJSONObject("hobbies"); System.out.println(hobbies); JSONArray staticJson = hobbies.getJSONArray("static"); System.out.println(staticJson); JSONObject today = (JSONObject) staticJson.get(0); System.out.println("today"+today); String mo = (String) today.get("morning"); System.out.println(mo); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
java解析json指定格式_java解析json格式文件
最新推荐文章于 2024-01-12 22:12:57 发布