我正在构建一个Web应用程序,我想在其中显示iTunes 10首歌曲和iTunes前10张专辑。我使用https://rss.itunes.apple.com/链接来生成它并从XML更改为json。JSON中的iTunes RSS源 - 阅读JAVA Webapps
http://itunes.apple.com/au/rss/topsongs/limit=10/json
我从上面的链接获得JSON。并且可以在JSON查看器中查看
http://jsonviewer.stack.hu/#http://itunes.apple.com/au/rss/topsongs/limit=10/json
不过,我很迷惑于如何读取JSON对象,这样我可以得到所需的字段。 (entry> title)
我能够进入条目并循环访问数组以获取所有标题。但是我不确定如何获得标签。
URL url = new URL("http://itunes.apple.com/au/rss/topsongs/limit=10/json");
URLConnection connection = url.openConnection();
String line;
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while((line = reader.readLine()) != null) {
builder.append(line);
}
JSONObject itunesJsonObject = new JSONObject(builder.toString());
JSONObject feedJsonOject = itunesJsonObject.getJSONObject("feed");
JSONArray arrayJsonObject = feedJsonOject.getJSONArray("entry");
List<String> list = new ArrayList<>();
for(int i = 0 ; i < arrayJsonObject.length() ; i++){
list.add(arrayJsonObject.getJSONObject(i).getString("title"));
}
for(String e: list){
log.debug("JSON Object : " + e.toString());
}
在log.debug中,我是下面包含标签的geeting。
JSON对象:{ “标记”: “快乐(从\” 卑鄙的我2 \ “) - 菲瑞威廉斯”}
JSON对象:{ “标签”: “小号 - 詹森DERULO”}
JSON对象:{ “标签”: “粗鲁 - 神奇!”}
JSON对象:{ “标签”: “我的全部 - 约翰传奇”}
JSON对象:{ “标签”: “免费(feat。EmeliSandé) - Rudimental”}
JSON对象:{“label”:“I See Fire - Ed Sheeran”}
JSON对象:{“label”:“Timber(feat。柯$公顷) - Pitbull的 “}
JSON对象:{” 标签 “:” 只有上帝知道 - MKTO “}
JSON对象:{” 标签 “:” 如鼓 - 盖伊塞巴斯蒂安“}
JSON对象:{“标签”:“嘿,兄弟 - 航空工业第二集团公司”}
我的问题是如何得到的只是不花括号和文字标签标题 此外,在JSON条目:IM:收藏有三个。对象(im:name,link和im:contentType)。如何独立获取它们。
感谢您的帮助提前。
辉煌。工作完美。感谢你的回答。 –