import java.text.ParseException; import org.json.JSONArray; import org.json.JSONObject; public class TestJsonArray { public static void main(String[] args) throws ParseException { String jsonStr = "[{\"a\":123, \"b\":\"hello\", \"x\":[{\"inner\":\"Inner JSONObject\"}]}]"; JSONArray jsonArray = new JSONArray(jsonStr); JSONObject jsonObj = jsonArray.getJSONObject(0); System.out.println(jsonObj); int a = jsonObj.getInt("a"); String b = jsonObj.getString("b"); JSONArray jsonArrayX = jsonObj.getJSONArray("x"); System.out.println(a); System.out.println(b); System.out.println(jsonArrayX); System.out.println(jsonArrayX.getJSONObject(0).getString("inner")); } }
转载于:https://www.cnblogs.com/hello-yao-ge/p/5949203.html