我试图从用户那里获得歌曲的标题' soundcloud喜欢但是当我将文本文件传输到JSONArray(不允许我转移到JSONObject)时,我似乎无法找到获取单个元素的方法,在这种情况下" title& #34;
try {
Object obj = parser.parse(new FileReader(
"/switched this out but do have correct path"));
JSONArray jsonArray = (JSONArray) obj;
System.out.println(jsonArray.size());
System.out.println(jsonArray.iterator());
System.out.println(jsonArray.get(10));
Iterator<JSONObject> iterator = jsonArray.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
} catch (IOException | ParseException e) {
System.out.println("Something went wrong");
}
这是jsonArray.get(10)的输出,你可以看到涉及大量的元素。
{"comment_count":40,"downloadable":false,"release":null,"created_at":"2016\/03\/31 04:41:13 +0000","description":"Other channels you might like...\r\n▶ @XXX\r\n▶ @YourSecret\r\n▶ @Future\r\n\r\nFree Download: http:\/\/dl.aia.ag\/no-will-hudgrove\r\nSpotify: http:\/\/spotify.aia.ag\/1MCU37t\r\niTunes: http:\/\/buy.aia.ag\/1pMeuob\r\n--------------------------------------------------------------------------------\r\nFollow @no-will\r\nhttp:\/\/twitter.com\/noahwilliamson\r\n\r\n♫ Listen on Spotify:\r\nhttp:\/\/aia.ag\/AIA-Spotify\r\n\r\n♫ Support AIA:\r\nhttp:\/\/aia.ag\/AIA-SC\r\nhttp:\/\/aia.ag\/AIA-FB\r\nhttp:\/\/aia.ag\/AIA-YT\r\nhttp:\/\/aia.ag\/AIA-IG\r\nhttp:\/\/aia.ag\/AIA-TW\r\n--------------------------------------------------------------------------------\r\nSubmit music to the email found in the sidebar of the channel info!","original_content_size":10463196,"title":"No Will - Hudgrove","track_type":"original","duration":242909,"video_url":null,"original_format":"mp3","artwork_url":"https:\/\/i1.sndcdn.com\/artworks-000155542480-tbt08v-large.jpg","streamable":true,"tag_list":"Chillwave Chillout Ambient Melodic Instrumental Beats Daydream Sexy \"Free Download\"","release_month":null,"genre":"Chill","release_day":null,"id":256391781,"state":"finished","last_modified":"2016\/04\/28 10:55:20 +0000","label_name":null,"commentable":true,"bpm":null,"favoritings_count":1981,"kind":"track","purchase_url":"http:\/\/dl.aia.ag\/no-will-hudgrove","release_year":null,"key_signature":null,"isrc":null,"sharing":"public","uri":"https:\/\/api.soundcloud.com\/tracks\/256391781","attachments_uri":"https:\/\/api.soundcloud.com\/tracks\/256391781\/attachments","download_count":0,"license":"all-rights-reserved","purchase_title":"Free Download","user_id":74594593,"embeddable_by":"all","waveform_url":"https:\/\/w1.sndcdn.com\/ucn5ZQ0XdvuY_m.png","permalink":"no-will-hudgrove","permalink_url":"http:\/\/soundcloud.com\/chill\/no-will-hudgrove","user":{"avatar_url":"https:\/\/i1.sndcdn.com\/avatars-000199251203-cuua5s-large.jpg","kind":"user","id":74594593,"permalink":"chill","permalink_url":"http:\/\/soundcloud.com\/chill","last_modified":"2016\/05\/02 22:33:11 +0000","uri":"https:\/\/api.soundcloud.com\/users\/74594593","username":"chill"},"label_id":null,"stream_url":"https:\/\/api.soundcloud.com\/tracks\/256391781\/stream","playback_count":6739}
我想获得&#34;标题&#34;来自那样的对象^^^有什么想法吗?
P.S。迭代器循环打印出我粘贴在上面的39个总对象
答案 0 :(得分:0)
我需要更多关于此信息的信息。
据我所知,问题是将数据退出?
它看起来像这样:
SELECT s.developer_id
FROM skills s
JOIN skills s2 ON (s2.developer_id = s.developer_id)
WHERE s.language_id = 256 AND s2.language_id = 85
然后字符串将是标题的值。
如果这不是您正在寻找的答案,请澄清并再次问我。
答案 1 :(得分:0)
通过从每个JSONArray元素中生成JSONObjects解决此问题,然后使用JSONObjectName.get(“elementName”)
答案 2 :(得分:0)
1)不确定,但也许你的json中有一些字符集问题。
试试这个:
JSONObject obj = (JSONObject)jsonArray.get(10);