我正在使用本教程:http ://www.androidhive.info/2012/10/android-multilevel-listview-tutorial/
在这里,他创建了 3 个不同的 JSON,
首先,获取专辑列表
二、获取专辑下的歌曲列表
三、显示单曲信息
但我需要在这里做一个小改动,而不是 3 个不同的 JSON,我想为专辑和歌曲使用单个 JSON,并且我也创建了我的演示 JSON,我能够获取专辑列表但没有得到列表歌曲,我的 JSON 看起来像这样,我使用的代码与他为客户端编写的代码相同:
我的.json:
[
{
"id": 1,
"name": "127 Hours",
"album": "127 Hours",
"songs": [
{
"id": 1,
"name": "Never Hear Surf Music Again",
"duration": "5:52"
},
{
"id": 2,
"name": "The Canyon",
"duration": "3:01"
}
]
}
]
日志猫:
06-18 06:36:56.318: D/dalvikvm(793): GC_CONCURRENT freed 143K, 7% free 3745K/4012K, paused 6ms+127ms, total 243ms
06-18 06:36:56.399: I/Choreographer(793): Skipped 37 frames! The application may be doing too much work on its main thread.
06-18 06:36:56.689: I/Choreographer(793): Skipped 66 frames! The application may be doing too much work on its main thread.
06-18 06:36:57.508: D/Track List JSON:(793): [
06-18 06:36:57.508: D/Track List JSON:(793): {
06-18 06:36:57.508: D/Track List JSON:(793): "id":1,
06-18 06:36:57.508: D/Track List JSON:(793): "name":"127 Hours",
06-18 06:36:57.508: D/Track List JSON:(793): "album":"127 Hours",
06-18 06:36:57.508: D/Track List JSON:(793): "songs":[
06-18 06:36:57.508: D/Track List JSON:(793): {
06-18 06:36:57.508: D/Track List JSON:(793): "id":1,
06-18 06:36:57.508: D/Track List JSON:(793): "name":"Never Hear Surf Music Again",
06-18 06:36:57.508: D/Track List JSON:(793): "duration":"5:52"
06-18 06:36:57.508: D/Track List JSON:(793): },
06-18 06:36:57.508: D/Track List JSON:(793): {
06-18 06:36:57.508: D/Track List JSON:(793): "id":2,
06-18 06:36:57.508: D/Track List JSON:(793): "name":"The Canyon",
06-18 06:36:57.508: D/Track List JSON:(793): "duration":"3:01"
06-18 06:36:57.508: D/Track List JSON:(793): }
06-18 06:36:57.508: D/Track List JSON:(793): ]
06-18 06:36:57.508: D/Track List JSON:(793): }
06-18 06:36:57.508: D/Track List JSON:(793): ]
06-18 06:36:57.668: W/System.err(793): org.json.JSONException: Value [{"id":1,"songs":[{"id":1,"duration":"5:52","name":"Never Hear Surf Music Again"},{"id":2,"duration":"3:01","name":"The Canyon"}],"album":"127 Hours","name":"127 Hours"}] of type org.json.JSONArray cannot be converted to JSONObject
06-18 06:36:57.668: W/System.err(793): at org.json.JSON.typeMismatch(JSON.java:111)
06-18 06:36:57.668: W/System.err(793): at org.json.JSONObject.<init>(JSONObject.java:158)
06-18 06:36:57.788: W/System.err(793): at org.json.JSONObject.<init>(JSONObject.java:171)
06-18 06:36:57.888: W/System.err(793): at com.example.androidhive.TrackListActivity$LoadTracks.doInBackground(TrackListActivity.java:155)
06-18 06:36:57.898: W/System.err(793): at com.example.androidhive.TrackListActivity$LoadTracks.doInBackground(TrackListActivity.java:1)
06-18 06:36:57.898: W/System.err(793): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-18 06:36:57.898: W/System.err(793): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-18 06:36:57.898: W/System.err(793): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-18 06:36:57.898: W/System.err(793): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-18 06:36:57.909: W/System.err(793): at java.lang.Thread.run(Thread.java:856)
注意:我可以获取专辑列表,但每当我点击任何专辑时都没有歌曲