-1

我有这个 JSON 结果页面,我想用 .java 解析它

[
{
"kind": "track",
"id": 12429087,
"created_at": "2011/03/23 19:10:55 +0000",
"user_id": 2297976,
"duration": 473257,
"commentable": true,
"state": "finished",
"original_content_size": 19029935,
"sharing": "public",
"tag_list": "",
"permalink": "adikta-llega-la-calma-en-vivo",
"streamable": true,
"embeddable_by": "all",
"downloadable": true,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "",
"title": "ADIKTA - LLEGA LA CALMA en vivo 6",
"description": "",
"label_name": "",
"release": "",
"track_type": "",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "mp3",
"license": "all-rights-reserved",
"uri": "http://api.soundcloud.com/tracks/12429087",
"user": {
  "id": 2297976,
  "kind": "user",
  "permalink": "adikta",
  "username": "adikta",
  "uri": "http://api.soundcloud.com/users/2297976",
  "permalink_url": "http://soundcloud.com/adikta",
  "avatar_url": "http://i1.sndcdn.com/avatars-000002155791-15emwj-large.jpg?3eddc42"
},
"permalink_url": "http://soundcloud.com/adikta/adikta-llega-la-calma-en-vivo",
"artwork_url": "http://i1.sndcdn.com/artworks-000005792200-72zfn4-large.jpg?3eddc42",
"waveform_url": "http://w1.sndcdn.com/hPYrb5G8V4an_m.png",
"stream_url": "http://api.soundcloud.com/tracks/12429087/stream",
"download_url": "http://api.soundcloud.com/tracks/12429087/download",
"playback_count": 114,
"download_count": 19,
"favoritings_count": 1,
"comment_count": 0,
"attachments_uri": "http://api.soundcloud.com/tracks/12429087/attachments"

},

这是我的 .java 类(android)代码:

            try {
            JSONObject respObj = new JSONObject(result);
            JSONObject topTracksObj = respObj.getJSONObject("tracks");
            JSONArray tracks = topTracksObj.getJSONArray("track");
            for(int i=0; i<tracks.length(); i++) {
                JSONObject track = tracks.getJSONObject(i); 
                String trackName = track.getString("permalink");
                String trackUrl = track.getString("permalink_url");
                JSONObject artistObj = track.getJSONObject("user");
                String artistName = artistObj.getString("permalink");
                String artistUrl = artistObj.getString("uri");
                String imageUrl;....

但我找不到任何解决方案来解析或导航这个没有 id 的 JSON 目录。我使用的 api 是 soundcloud,但我也找不到答案。任何帮助,将不胜感激。有什么建议吗?提前致谢

4

1 回答 1

1

请找到下面提到的代码:

String str = "<YOUR_JSON_STRING>";
        JSONArray jArrayObject;
        try {
            jArrayObject = new JSONArray(str);
            for (int i = 0; i<jArrayObject.length(); i++) {
                Log.d("kind==", jArrayObject.getJSONObject(i).getString("kind").toString());
                Log.d("id==", jArrayObject.getJSONObject(i).getString("id").toString());
                Log.d("created_at==", jArrayObject.getJSONObject(i).getString("created_at").toString());
                JSONObject jObj = new JSONObject(jArrayObject.getJSONObject(i).getString("user").toString());
                Log.d("id==", jObj.getString("id").toString());
                Log.d("kind==", jObj.getString("kind").toString());
                Log.d("permalink==", jObj.getString("permalink").toString());
                Log.d("username==", jObj.getString("username").toString());
                Log.d("permalink_url==", jObj.getString("permalink_url").toString());
                Log.d("avatar_url==", jObj.getString("avatar_url").toString());


            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }        
于 2013-10-23T07:46:21.873 回答