JSONObject json;
try {
json = new JSONObject("{\"limit\":10,\"offset\":6,\"totalNumberOfItems\":54,\"items\":[{\"id\":22120604,\"title\":\"Hey Brother\",\"<span style="white-space:pre"> </span>album\":{\"id\":22120601,\"title\":\"True\",\"cover\":\"365fae45-0cc7-487b-a4d7-b62bb0394062\"},\"artist<span style="white-space:pre"> </span>\":{\"id\":3637201,\"name\":\"Avicii\",\"type\":\"MAIN\"}}]}");
JSONArray jSONArray = json.getJSONArray("items");
for (int i = 0; i < jSONArray.length(); i++) {
JSONObject jSONObjectresult = jSONArray.getJSONObject(i);
System.out.println(jSONObjectresult.getString("artist"));
json = new JSONObject(jSONObjectresult.getString("artist"));
System.out.println("id="+json.getInt("id"));
System.out.println("name="+json.getString("name"));
System.out.println("type="+json.getString("type"));
}
} catch (JSONException e) {
e.printStackTrace();
}
--直接运行
java 解析json小案例
最新推荐文章于 2021-03-10 04:54:06 发布